9:41 am

May 2, 2015

Hi,
I have upadated a channel without any problem and I would like to read it back with another ESP8266.
Here is my code (replace MyAPIkey with the right value)
wifi.setmode(wifi.STATION)
wifi.sta.autoconnect(1)
function DoIt()
conn = nil
conn = net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)success = true print("receive"..payload) end) --send and deep sleep
conn:on("connection",
function(conn, payload)
print("Connected TS")
conn:send('GET /channels/37123/fields/1/last?key=MyAPIKEY'..'HTTP/1.1
\
Host: api.thingspeak.com
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
')
end)
conn:on("disconnection", function(conn, payload) print('Disconnected') end)
conn:connect(80,'184.106.153.149')
end
-- every 5 second, check thingspeak
tmr.alarm(0, 5000, 1, function() DoIt() end)
This code is working but always returns "-1" as the field1 value...
If I ask the same request directly from my browser then it works...
So should be a problem into the GET syntax but where ?
Thanks for your help
JP
11:57 am

May 19, 2015

freedom2000 said
I have upadated a channel without any problem and I would like to read it back with another ESP8266.
Here is my code (replace MyAPIkey with the right value)conn:send('GET /channels/37123/fields/1/last?key=MyAPIKEY'..'HTTP/1.1
\
Host: api.thingspeak.com
Accept: */*
User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)')
end)This code is working but always returns "-1" as the field1 value...
If I ask the same request directly from my browser then it works...So should be a problem into the GET syntax but where ?
Thanks for your help
JP
Interesting because I will by trying something similar soon. I dont have a definitive answer because I have not tried it out, however in your conn:send string after you send your API key would it need a delimiter (if that is the correct term) before sending 'HTTP1/1 ??
Dave
8:24 pm

May 19, 2015

Just an update, what was missing was a couple of carriage returns. I removed all the extra formatting to cut down on bandwidth. What works for me was:
edit: on the line ..READKEY..' should read 'slash r slash n single quote bracket. Not sure how to include a couple of cr\lf without it becoming mangled in this post.
WRITEKEY="YOUR_WRITE_KEY" -- set your thingspeak.com keys
READKEY="YOUR_READ_KEY"
CHANNEL="YOUR_CHANNEL_ID"
wifi.setmode(wifi.STATION)
--wifi.sta.config("yourSSID","yourPASSWORD")
wifi.sta.connect()
tmr.delay(1000000)
function readTSfield()
conn = nil
conn = net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)success = true print("received "..payload) end)
conn:on("connection",
function(conn, payload)
print("Connected TS")
conn:send('GET /channels/'..CHANNEL..'/fields/1/last?key='..READKEY..'
')
end)
conn:on("disconnection", function(conn, payload) print('Disconnected') end)
conn:connect(80,'184.106.153.149')
end
tmr.alarm(0, 5000, 1, function() readTSfield() end)
HTH, Dave
Most Users Ever Online: 166
Currently Online:
30 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
kusmumichael, petersmith99, Rambant, blakeharriss09, optisol, Niyonzima FilsModerators: cstapels: 460
Administrators: Hans: 405, lee: 457