print(str(ser.readline())) # pauses the LoRaWAN stack functionality to allow transceiver (radio) configuration # must be called before any radio transmission or reception print('cmd> mac pause') ser.write(b'mac pause\r\n') print(str(ser.readline())) print('----------------------------------') try: while True: time.sleep(8) air = g3sensor() pmdata = 0 pmdata = air.read("/dev/ttyAMA0") pm25 = str(pmdata[5]) rawinput = pm25 try: byte_rawinput = bytes(rawinput + "\r\n") except: byte_rawinput = bytes(rawinput + "\r\n", encoding="UTF-8") cmd = "radio tx " _length, _payload = packer.Pack_Str(rawinput) if int(_length) < int(MAX_PAYLOAD_LENGTH): print("Time: " + str(time.ctime()))
#!/usr/bin/python import time import datetime import os import httplib, urllib import g3 air=g3.g3sensor() while True: try: pmdata=air.read("/dev/ttyAMA0") except: pmdata=[0,0,0,0,0,0] continue # thingspeak params = urllib.urlencode({'field1': pmdata[3], 'field2': pmdata[4], 'field3': pmdata[5], 'key':'YOUR WRITE KEY'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} try: tconn = httplib.HTTPConnection("api.thingspeak.com:80") tconn.request("POST", "/update", params, headers) response = tconn.getresponse() data = response.read() tconn.close() except: continue time.sleep(600)