diff --git a/Meteo/a_meteo2-tests.lua b/Meteo/a_meteo2-tests.lua index b6bc587..7cf05fe 100644 --- a/Meteo/a_meteo2-tests.lua +++ b/Meteo/a_meteo2-tests.lua @@ -5,20 +5,32 @@ -- les conditions pour toutes les heures la journée -- Source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/sjson-streaming.lua -print("\n a_meteo2-tests.lua zf190303.1440 \n") +print("\n a_meteo2-tests.lua zf190304.1703 \n") + +dofile("a_meteo3-tests.lua") + +--zhost="www.prevision-meteo.ch" +--zport=80 +--zpath="/services/json/lausanne" + +zhost="192.168.0.154" +zport=8080 +zpath="/meteo.lausanne.190302.1231.json" --local s = tls.createConnection() local s = net.createConnection() + s:on("connection", function(sck, c) -- sck:send("GET /repos/nodemcu/nodemcu-firmware/git/trees/master HTTP/1.0\r\nUser-agent: nodemcu/0.1\r\nHost: api.github.com\r\nConnection: close\r\nAccept: application/json\r\n\r\n") -- sck:send("GET /services/json/lausanne HTTP/1.0\r\nHost: www.prevision-meteo.ch\r\n\r\n") - sck:send("GET /services/json/Lausanne HTTP/1.0\r\nHost: www.prevision-meteo.ch\r\n\r\n") + sck:send("GET "..zpath.." HTTP/1.0\r\nHost: "..zhost.."\r\n\r\n") end) --- The receive callback is somewhat gnarly as it has to deal with find the end of the header --- and having the newline sequence split across packets +zcmpt=1 s:on("receive", function(sck, c) - print(c) + print("zcmpt: ",zcmpt,string.len(c),string.sub(c,1,100)) + ztoto(c) + zcmpt=zcmpt+1 end) local function getresult() @@ -27,9 +39,5 @@ end s:on("disconnection", getresult) s:on("reconnection", getresult) - --- Make it all happen! ---s:connect(443, "api.github.com") ---s:connect(443, "www.prevision-meteo.ch") -s:connect(80, "www.prevision-meteo.ch") +s:connect(zport, zhost) diff --git a/Meteo/a_meteo3-tests.lua b/Meteo/a_meteo3-tests.lua index ecda394..06bbf0e 100644 --- a/Meteo/a_meteo3-tests.lua +++ b/Meteo/a_meteo3-tests.lua @@ -11,38 +11,76 @@ function set_json() end function zget_json_key() - print("len1: "..string.len(zjson)) - zjson_key='"'..zh..'H00":{' - print("zjson_key: "..zjson_key) - p1=string.find(zjson, zjson_key) - print("p1: "..p1) - zjson=string.sub(zjson,p1) - print("zjson: ",zjson) - p1,p2=string.find(zjson, '"CONDITION_KEY":"') - print(p1,p2) - p3=string.find(zjson, '","',p2) - print(p3) - ztoto=string.sub(zjson,p2,p3) - print(ztoto) - print("len2: "..string.len(zjson)) + print("coucou2",zjson_stat) + if zjson_stat==1 then + p1=0 + p1=string.find(zjson, [["hourly_data":{]]) + print("JSON header: "..p1) + if p1>0 then + zjson=string.sub(zjson,p1) + print(string.sub(zjson,1,100)) + print("\n\nc'est parti...\n\n") + zjson_stat=2 + else + zjson=string.sub(zjson,string.len(zjson)-20) + end + end + if zjson_stat==2 then + print("len1: "..string.len(zjson)) + zjson_key='"'..zh..'H00":{' + print("zjson_key: "..zjson_key) + p1=string.find(zjson, zjson_key) + print("p1: "..p1) + zjson=string.sub(zjson,p1) + print("zjson: ",string.sub(zjson,1,100)) + p1,p2=string.find(zjson, '"CONDITION_KEY":"') + print(p1,p2) + p3=string.find(zjson, '","',p2) + print(p3) + ztoto=string.sub(zjson,p2,p3) + print(ztoto) + print("len2: "..string.len(zjson)) + end end -set_json() -p1=string.find(zjson, [["hourly_data":{]]) -print(p1) -zjson=string.sub(zjson,p1) -print(zjson) -print("\n\nc'est parti...\n\n") +zh=0 +zjson_stat=1 +zjson="" + +function ztoto(c) + print("coucou") + if zjson=="" then + zjson=c + else + zjson=zjson..c + end + print("zh: ",zh,"len(zjson",string.len(zjson)) + while zh<=5 and string.len(zjson)>500 do + zget_json_key() + zh=zh+1 + end + if zh>5 then + zjson="" + end +end + + +--set_json() +--zjson_stat=1 +--zget_json_all_keys() + --[[ set_json() +zjson_stat=1 zh=1 zget_json_key() zh=2 zget_json_key() set_json() +zjson_stat=1 zh=0 for i=0, 5 do zget_json_key() diff --git a/Meteo/wifi_get_ip.lua b/Meteo/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/Meteo/wifi_get_ip.lua @@ -0,0 +1,12 @@ +-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi +print("\n wifi_get_ip.lua zf181119.2318 \n") + +wifitimer1=tmr.create() +tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + else + tmr.stop(wifitimer1) + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + end +end)