if adc.force_init_mode(adc.INIT_VDD33) then node.restart() end -- Begin WiFi configuration wifi.setmode(wifi.STATIONAP) wifi.ap.config({ssid="ESP"..node.chipid(), pwd=""..node.chipid()}) wifi.ap.setip({ip="192.168.111.1", netmask="255.255.255.0"}) wifi.sta.config("Moon On AirPort", "MoonOnAP", 1) collectgarbage() -- End WiFi configuration function init_display() local sda = 2 local sdl = 1 local sla = 0x3c i2c.setup(0,sda,sdl, i2c.SLOW) disp = u8g.ssd1306_128x64_i2c(sla) disp:setFont(u8g.font_6x10) disp:setFontRefHeightExtendedText() disp:setDefaultForegroundColor() disp:setFontPosTop() end -- Start the draw loop with the draw implementation in the provided function callback function updateDisplay(func) -- Draws one page and schedules the next page, if there is one local function drawPages() local success, data = pcall(func) if (not success) then print(data) end if (disp:nextPage() == true) then node.task.post(drawPages) end end -- Restart the draw loop and start drawing pages disp:firstPage() node.task.post(drawPages) end function drawSystemStatus() disp:drawStr(0, 0, 'Wifi station MAC addr:') disp:drawStr(0, 8, wifi.sta.getmac()) local status = wifi.sta.status() if status == 0 then disp:drawStr(0, 24, 'STA_IDLE ') elseif status == 1 then disp:drawStr(0, 24, 'STA_CONNECTING') elseif status == 2 then disp:drawStr(0, 24, 'STA_WRONGPWD ') elseif status == 3 then disp:drawStr(0, 24, 'STA_APNOTFOUND') elseif status == 4 then disp:drawStr(0, 24, 'STA_FAIL ') elseif status == 5 then disp:drawStr(0, 24, 'IP: '..wifi.sta.getip()..' '..wifi.sta.getrssi()..' dB') end disp:drawStr(0, 40, 'Heap: '..node.heap()..' '..adc.readvdd33()..' mV') remaining, used, total = file.fsinfo() disp:drawStr(0, 56, 'FS: '..used..'/'..total..' bytes') end local drawDemo = { drawSystemStatus } function demoLoop() -- Start the draw loop with one of the demo functions local f = table.remove(drawDemo,1) updateDisplay(f) table.insert(drawDemo,f) end function startOLED() -- Initialise the display init_display() -- Draw demo page immediately and then schedule an update every 5 seconds. -- To test your own drawXYZ function, disable the next two lines and call updateDisplay(drawXYZ) instead. demoLoop() tmr.alarm(4, 1000, 1, demoLoop) end startOLED()