Only problem is now I get the dreaded " not enough memory" error on trying to compile.
I've eliminated all local variables and all print() calls but still can't get it small enough to compile.
Any ideas?
Explore... Chat... Share...
-- your offset to UTC
--local UTC_OFFSET = -6
-- Enter your city, check openweathermap.org
local CITY = "5429032"
-- Get an APP ID on openweathermap.org
local APPID = "xxxxxxxxx"
-- Update interval in minutes
--local INTERVAL = 10
function init_i2c_display()
-- SDA and SCL can be assigned freely to available GPIOs
-- sda = 5 -- GPIO14
-- scl = 6 -- GPIO12
-- sla = 0x3c
i2c.setup(0, 5, 6, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(0x3c)
end
function prepare()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
function updateWeather()
-- print("Updating weather")
local conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
local lastUpdate = string.sub(payload,string.find(payload,"Date: ")+23,string.find(payload,"Date: ")+31)
local hour = string.sub(lastUpdate, 0, 2) - 6
lastUpdate = hour..string.sub(lastUpdate, 3, 9)
local payload = string.match(payload, "{.*}")
print(payload)
weather = nil
weather = cjson.decode(payload)
local icon = weather.weather[1].icon
icon = string.gsub(icon, "n", "d")
file.open(icon..".MONO", "r")
xbm_data = file.read()
file.close()
payload = nil
conn:close()
conn = nil
drawWeather(xbm_data, weather, lastUpdate)
end )
conn:connect(80,ip)
-- conn:send("GET /data/2.5/weather?q=5429032&units=metric&APPID=xxxxxxx"
conn:send("GET /data/2.5/weather?q="..CITY.."&units=metric&APPID="..APPID
.." HTTP/1.1\r\n"
.."Host: api.openweathermap.org\r\n"
.."Connection: close\r\n"
.."Accept: */*\r\n"
.."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n"
.."\r\n")
conn = nil
end
init_i2c_display()
prepare()
sk=net.createConnection(net.TCP, 0)
--sk:dns("www.google.com",dnsIsWorking)
sk:dns("api.openweathermap.org",function(conn,ip) print("OW = "..ip) end)
sk = nil
updateWeather()
function drawWeather(xbmData, weather, lastUpdate)
disp:firstPage()
repeat
if weather ~= nil then
disp:drawXBM( 0, 0, 60, 60, xbm_data )
disp:setScale2x2()
disp:drawStr(35,5, math.floor((weather.main.temp * 2)+32).." f")
disp:drawStr(35,15, weather.main.humidity.."%")
disp:undoScale()
disp:drawStr(70,52, lastUpdate)
end
until disp:nextPage() == false
end
tmr.alarm(1, 10 * 60000, 1, function()
ip = wifi.sta.getip()
if ip=="0.0.0.0" or ip==nil then
-- print("connecting to AP...")
else
-- print("Loading weather...")
updateWeather()
end
end )
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]