async def MSetup(self, aPath: str, aParam: list): Vars = ConfApp.Keys() self._ShowTree(Vars) if (not await self.AskYN('Continue')): return R = {} Items = [ 'WiFi Access', [['STA_ESSID', 'SSID', 'oster.com.ua'], ['STA_Paswd', 'Password*', '']] ] R.update(await self.Input(Items, Vars)) Items = [ 'Mqtt Server', [['Mqtt_Host', 'Host', 'vpn2.oster.com.ua'], ['Mqtt_Port', 'Port', 1883], ['Mqtt_Login', 'Login', ''], ['Mqtt_Paswd', 'Password', '']] ] R.update(await self.Input(Items, Vars)) self._ShowTree(R) if (await self.AskYN('Save')): ConfApp.update(R) ConfApp.Save() print('Saved')
def Main(aConf) -> tuple: from App import ConfApp if (not ConfApp.STA_ESSID): from IncP.Captive import TCaptive Obj = TCaptive() Task = Obj.Run(ConfApp.get('AP_Paswd', '12345678')) return (Obj, Task)
async def DoUrl(aParent, aReader: asyncio.StreamReader, aWriter: asyncio.StreamWriter, aHead: dict): LenData = int(aHead.get('content-length', '0')) if (LenData > 0): R = 'about to reboot' Data = await aReader.read(LenData) Query = QueryToDict(Data.decode('utf-8')) ConfApp['STA_ESSID'] = Query.get('_STA_ESSID') ConfApp['STA_Paswd'] = Query.get('_STA_Paswd') ConfApp.Save() Reset() else: R = 'No data' await aParent.Answer(aWriter, 200, 'txt', R)
async def Connector(self): if (not await self.IsOk()): try: await self.Connect(ConfApp.STA_ESSID, ConfApp.STA_Paswd, ConfApp.STA_Net) except Exception as E: Log.Print(1, 'x', 'Connector()', E) Ok = await self.IsOk() if (self.Last != Ok): self.Last = Ok await self.Post(int(Ok)) if (Ok): self.Event.set() SetTime(ConfApp.get('TZone', 2)) else: self.Event.clear()
def Main(aConf) -> tuple: import bluetooth from micropython import const from IncP.BLE import GetAdvPayload from .Main import TBleEx from App import ConfApp # org.bluetooth.service.environmental_sensing _ENV_SENSE_UUID = bluetooth.UUID(0x181A) # org.bluetooth.characteristic.gap.appearance.xml _ADV_APPEARANCE_GENERIC_THERMOMETER = const(0x300) Payload = GetAdvPayload(aName=ConfApp.get('BLE_Name', 'MyBLE'), aServices=[_ENV_SENSE_UUID], aAppearance=_ADV_APPEARANCE_GENERIC_THERMOMETER) Obj = TBleEx(Payload) return (Obj, Obj.Run())
async def Exec(self) -> dict: return ConfApp.Keys()
async def IsOk(self) -> bool: Host = ConfApp.get('WatchHost', self.IF.ifconfig()[2]) # or gateway Res = (self.IF.isconnected) and (await CheckHost(Host, 80, 3)) return bool(Res) # (None and False) = None
async def Run(self, aSleep: float = 1.0): ConnSTA = Plugin.Find('ConnSTA')[0] self.Mqtt = Mqtt = MQTTClient('%s-%s' % (cName, ConnSTA.Mac()) , ConfApp.Mqtt_Host, ConfApp.get('Mqtt_Port', 1883), ConfApp.Mqtt_User, ConfApp.Mqtt_Passw) Mqtt.set_callback(self.DoSubscribe) while True: try: await ConnSTA.Event.wait() Mqtt.disconnect() await asyncio.sleep(1) Mqtt.connect() await Mqtt.subscribe('%s/sub/#' % (cName)) while True: # simlify nesting. too many recursion #await Mqtt.check_msg() Mqtt.sock.setblocking(False) await Mqtt.wait_msg() await asyncio.sleep(aSleep) except Exception as E: Log.Print(1, 'x', 'TMqtt.Run()', E) await asyncio.sleep(aSleep)
async def Exec(self, aUrl: str) -> dict: R = await TApi.DownloadList(aUrl) return {'result': R, 'alias': ConfApp.get('Alias'), 'hint': 'Reset ?'}