def getWifiOption(): wifiList = WiFi.getAllWifi() result = "" if wifiList is None: return None for i in range(0, len(wifiList)): result += '<option value="' + wifiList[i].ssid + '">' + wifiList[i].ssid + '</option>' return result
def main(): print("\n\nStarting - {}".format(machine.reset_cause())) while True: try: # Establish WiFi connection here interface = WiFi.connect_wifi(Config.wifi_ssid, Config.wifi_pass) if interface: print('Connected: ', interface.ifconfig()) # If we've got somewhere to write the data, read the sensors. # Deliberately do the DHT22 read last to maximise the chance of it having had long enough # to stabilise (only one read every 2 seconds) measurements = '' measurements += DS18B20.read_ds(Config.onewirePin, Config.location) measurements += DHT.read_dht(Config.dhtPin, Config.location) if measurements: print('\nSending to {}\n{}'.format(Config.database, measurements)) print('HTTP:{0}'.format( Influx.send(Config.database, measurements))) else: print('No sensors read successfully.') except KeyboardInterrupt: print("Caught keyboard interrupt") enter_sleep = False except Exception as e: import sys print("Unexpected error ", e) sys.print_exception(e) finally: if Config.deep_sleep: print('Zzzz....') Deepsleep.deep_sleep(Config.sampleTime * 1000) # This will only be executed if Deepsleep is disabled print('Dozing....') time.sleep(Config.sampleTime)
import cc1101_davis import davis_decode import utime import WiFi import machine gc.collect() DEBUG = True wifi_con = WiFi.NetSet('infra') wifi_con.readNetworkConfig() ips = wifi_con.connectInfra( wifi_con._SSID, wifi_con._PASS, wifi_con._TIMEOUT) if DEBUG: print("IPCONF: {}".format(ips)) gc.collect() davis = cc1101_davis.CC1101() davis.setRegisters() davis.setFrequency(davis.hopIndex) decoder = davis_decode.davisDecoder( wifi_con._INF_DB_WEATHER, wifi_con._INF_DB_STATUS, wifi_con._INF_DB_RAW) gc.collect()
def do_POST(self): postvars = self.parse_POST() if WiFi.connectToWifi(postvars['selectedWiFi'][0],postvars['wiFiPassword'][0]): self.do_GET(req="Connected.html",ssid=postvars['selectedWiFi'][0]) else: self.do_GET(req="Error.html",ssid=postvars['selectedWiFi'][0])
def slowLoop(): # mqtt.checkMessages() WiFi.tick()
def init_all_network(self): WiFi.connect()
import WiFi import Server from Credentials import WiFi_Credentials # Connect to WiFi. wifi = WiFi(WiFi_Credentials.SSID, WiFi_Credentials.PASS) wifi.connect() # Spin up the server and start listening for requests. server = Server() server.start()