Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. from __future__ import print_function
  2. from __future__ import unicode_literals
  3.  
  4. from twisted.internet.defer import inlineCallbacks
  5. from twisted.logger import Logger
  6.  
  7. from autobahn.twisted.util import sleep
  8. from autobahn.twisted.wamp import ApplicationSession
  9.  
  10. import time
  11. import json
  12.  
  13. #generator that yields values from file
  14. def ekg_gen(f):
  15.     row = f.readline()
  16.     while row:
  17.         yield row
  18.         row = f.readline()
  19.         if len(row) == 0:
  20.             f.seek(0,0)
  21.             row = f.readline()
  22.  
  23. class AppSession(ApplicationSession):
  24.  
  25.     log = Logger()
  26.  
  27.     @inlineCallbacks
  28.     def onJoin(self, details):
  29.         self.log.info("ECG node up")
  30.         with open("../ECG_data.txt", "r") as f: #simulated sample of an ECG-curve
  31.             value = ekg_gen(f)
  32.             while True:
  33.                 yield self.publish('com.testlab.ecg_update', json.dumps(next(value)))                
  34.                 yield sleep(0.02)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement