Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Test de connexion sur mon serveur et d'envoi de données
- -- Pour le moment, tests non concluants ...
- -- version nodemcu sur esp8266:
- conf = {
- wifi = { ssid='<my ssid>', pwd='<my pass>' },
- server = { port=80, ip='10.20.30.40', uri='/phytoepuration/formulaire-simple.php'},
- valeur = { temperature="00,00", humidite="00,00", compteur=0 }
- }
- id = 0
- function Requete_Post( Securite )
- -- ici, appel pour lire la temperature et l'humidite */
- lecture()
- mac=wifi.sta.getmac()
- t="num=" .. mac .. "&temperature=" .. conf.valeur.temperature .. "&humidite=" .. conf.valeur.humidite
- connexion = nil
- connexion = net.createConnection(net.TCP, Securite)
- connexion:on("receive", function(connexion, payloadout)
- if (string.find(payloadout, "Status: 200 OK") ~= nil) then
- print("Posted OK")
- end
- end)
- connexion:on("connection", function(connexion, payloadout)
- print ("Posting...")
- connexion:send("POST ".. conf.server.uri
- .. " HTTP/1.1\r\n"
- .. "Host: ".. conf.server.ip .. "\r\n"
- .. "Connection: close\r\n"
- .. "User-Agent: ESP8266-01 (compatible; esp8266 Lua)\r\n"
- .. "Accept: */*\r\n"
- .. "Content-Type: application/x-www-form-urlencoded\r\n"
- .. "Content-Length: " .. string.len(t) .. "\r\n\r\n"
- .. t)
- end)
- connexion:on("disconnection", function(connexion, payloadout)
- connexion:close()
- print("Requette close\n")
- collectgarbage()
- requete_ok=false
- end)
- connexion:connect(conf.server.port , conf.server.ip)
- end
- function reseau_wifi()
- wifi.setmode(wifi.STATION)
- wifi.sta.config(conf.wifi.ssid, conf.wifi.pwd)
- end
- function lecture()
- conf.valeur.temperature = string.format("%.2f", 26.23)
- conf.valeur.humidite = string.format("%.2f", 60.95)
- print("temp:"..conf.valeur.temperature.." / hum.:"..conf.valeur.humidite..".")
- end
- reseau_wifi()
- Requete_Post( 0 )
Advertisement
Add Comment
Please, Sign In to add comment