def pubDeviceBootToGoolgeCloud(): # Droneponics Start parser = ConfigParser() parser.read("/home/pi/droneponics/config/Google/" + drone.gethostname() + ".ini") device_id = parser.get('Google', 'device_id') _MQTT_TOPIC = '/devices/{}/events/deviceBoot'.format(device_id) payload = '{{ "bootTime": "{}", "deviceMAC": "{}", "deviceName": "{}", "deviceIP": "{}"}}'.format( int(time.time()), drone.get_mac(), drone.gethostname(), drone.get_ip()) return pubGoolgeCloud(_MQTT_TOPIC, payload)
def payload(payload): payload["bootTime"] = int(time.time()) payload["deviceMAC"] = drone.get_mac() payload["deviceIP"] = drone.get_ip() payload["gethostname"] = drone.gethostname()
blynk.run() timer.run() if bootup: blynk.virtual_write(250, "Boot") drone.pubDeviceBootToGoolgeCloud() blynk.set_property(250, 'color', drone.colours['ONLINE']) p = subprocess.Popen( ['i2cdetect', '-y', '1'], stdout=subprocess.PIPE, ) #cmdout = str(p.communicate()) for i in range(0, 9): blynk.virtual_write(98, str(p.stdout.readline()) + '\n') bootup = False blynk.set_property(251, "label", drone.gethostname()) blynk.virtual_write(251, drone.get_ip()) now = datetime.now() blynk.virtual_write(99, now.strftime("%d/%m/%Y %H:%M:%S")) blynk.virtual_write(systemLED, 255) #blynk.virtual_write(98, "clr") blynk.virtual_write(51, "EC Settings") blynk.virtual_write(52, "pH Settings") blynk.set_property(38, "label", "EC Trigger Level") blynk.set_property(48, "label", "pH Trigger Level") blynk.set_property(39, "label", "EC Mode") blynk.set_property(49, "label", "pH Mode") blynk.virtual_write(98, "System now updated and restarted " + '\n') blynk.virtual_write(255, 0) _log.info('Just Booted')
import sys import os sys.path.append('/home/pi/droneponics') import drone import liquidcrystal_i2c cols = 20 rows = 4 try: lcd = liquidcrystal_i2c.LiquidCrystal_I2C(0x27, 1, numlines=rows) lcd.printline(0, 'LCM2004 IIC V2'.center(cols)) lcd.printline(1, 'host-' + drone.gethostname()) lcd.printline(2, 'ip-' + drone.get_ip()) lcd.printline(3, 'liquidcrystal_i2c 1') print("Device found at address 27 on bus 1") except: print("no lcd on bus 1") try: lcd = liquidcrystal_i2c.LiquidCrystal_I2C(0x27, 0, numlines=rows) lcd.printline(0, 'LCM2004 IIC V2'.center(cols)) lcd.printline(1, 'host-' + drone.gethostname()) lcd.printline(2, 'ip-' + drone.get_ip()) lcd.printline(3, 'liquidcrystal_i2c 0') print("Device found at address 27 on bus 0") except: print("no lcd on bus 0")
def getBootPayload(__payload): __payload["bootTime"] = int(time.time()) __payload["deviceMAC"] = drone.get_mac() __payload["deviceIP"] = drone.get_ip() __payload["gethostname"] = drone.gethostname()
parser = ConfigParser() parser.read("/home/pi/droneponics/config/Google/"+drone.gethostname()+".ini") # tune console logging _log = logging.getLogger('GoogleLog') logFormatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s") consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) _log.addHandler(consoleHandler) _log.setLevel(parser.get('logging', 'logLevel', fallback=logging.DEBUG)) _log.critical("critical") _log.error("error") _log.warning("warning") _log.info("info") _log.debug("debug") _log.info("ConfigParser path = /home/pi/droneponics/config/Google/"+drone.gethostname()+".ini") _log.critical('{{ "ts": "{}", "deviceMAC": "{}", "deviceName": "{}", "deviceIP": "{}"}}'.format(int(time.time()), drone.get_mac(), drone.gethostname(), drone.get_ip())) payload = drone.dronePayload(_log) payload.add("deviceName", drone.gethostname()) payload.add("deviceIP", drone.get_ip()) payload.add("TestNone", None) _log.critical(payload.get())