validate_cs=cp.getboolean('nrf24','only_with_valid_checksum') save = True while True: pipe = [-1] recv_buffer = [] if radio.available(pipe): radio.read(recv_buffer) if(pipe[0]>=0): # bcount+=recv_buffer.length count+=1 frame= ''.join(chr(i) for i in recv_buffer) if(validate_cs): res=BayEOSFrame.parse_frame(frame) try: save=res['validChecksum'] except: save=False if(save): writer.save_frame(frame,origin=OriginTemplate % pipe[0]) if(len(led_pins)): start_new_thread(blink, (led_pins[0] if(pipe[0]>=len(led_pins)) else led_pins[pipe[0]],)) if((time.time()-last_stat)>60): writer.save([count,bcount]) last_stat=time.time() if(count==0): initNRF24(False) #Restart radio, when there was no frame the last minute!
#!/usr/bin/python # -*- coding: utf-8 -*- import baySerial from bayeosgatewayclient import BayEOSFrame ser = baySerial.BaySerial() ser.begin('/dev/ttyUSB0', 9600) while (True): frame = ser.getFrame() if (not frame == False): # print(frame) print(BayEOSFrame.parse_frame(frame['frame']))
"""Creates example BayEOS Frames.""" from bayeosgatewayclient import BayEOSFrame # Data Frames, simple data_frame_simple = BayEOSFrame.factory(0x1) data_frame_simple.create(values=(2, 5, 4), value_type=0x22) # Data Type Integer print data_frame_simple.parse() data_frame_simple.print_dict() data_frame_simple.print_hex() print BayEOSFrame.parse_frame(data_frame_simple.frame) # Data Frame with Channel Offset data_frame_offset = BayEOSFrame.factory() # 0x1 is default data_frame_offset.create([2.3, 4.5], value_type=0x01, offset=2) # Data Type float data_frame_offset.print_dict() # Data Frame with Channel Indices data_frame_indices = BayEOSFrame.factory() data_frame_indices.create(([3, 1], [2, 5]), value_type=0x41) # Data Type float data_frame_indices.print_dict() data_frame_indices2 = BayEOSFrame.factory() data_frame_indices2.create(((3, 1), (2, 5)), value_type=0x42) # Data Type Integer data_frame_indices2.print_dict() # Message Frames message_frame = BayEOSFrame().factory(0x4) message_frame.create(message="This is an important message.") message_frame.print_dict()
from os import path PATH = path.join(tempfile.gettempdir(),'bayeos-device') BACKUP_PATH = path.join(tempfile.gettempdir(),'bayeos-device-backup') NAME = 'Python-SampleFrames' URL = 'http://bayconf.bayceer.uni-bayreuth.de/gateway/frame/saveFlat' writer = BayEOSWriter(PATH,max_time=10,log_level=logging.DEBUG) writer.save_msg('Writer was started.') sender = BayEOSSender(PATH, NAME, URL,backup_path=BACKUP_PATH) sender.start() while True: data_frame_simple = BayEOSFrame.factory(0x1) data_frame_simple.create(values=(1, 5, 4), value_type=0x22) # Data Type Integer writer.save_frame(data_frame_simple.frame) routed_origin_frame = BayEOSFrame.factory(0xd) routed_origin_frame.create(origin="RoutedOrigin", nested_frame=data_frame_simple.frame) writer.save_frame(routed_origin_frame.frame) sleep(2) # in the second try - checksum frames are send # first direct - second nested in routed origin frame data_frame_simple = BayEOSFrame.factory(0x1) data_frame_simple.create(values=(2, 5, 4), value_type=0x22) # Data Type Integer checksum_frame = BayEOSFrame.factory(0xf) checksum_frame.create(data_frame_simple.frame) writer.save_frame(checksum_frame.frame) sleep(2)