-->
Page 8 of 9

Re: post to thingspeak.com

PostPosted: Wed Sep 16, 2015 5:30 pm
by kniazio
Big, big thanks

How to configure Thingspeak to work with the Notify My Android.
Some examples?

I already did.
Here's an example Thinghttp:
URL - https://www.notifymyandroid.com/publicapi/notify
Method - POST
Content type - application/x-www-form-urlencoded
Host - notifymyandroid.com

Body - apikey=your_api_key&application=your_aplikation_name&event=your_message&description=your_mesage_description&priority=0

Re: post to thingspeak.com

PostPosted: Wed Sep 23, 2015 8:37 pm
by toyorg
Can someone help me? What's wrong with this code? I always got this "Got disconnection...", WiFi connection is OK.

Code: Select allapiKey = "xXx" -- Add thingspeak api key
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,"184.106.153.149")
conn:send("GET /update?key="..apiKey.."&field1="..tempin.."&field2="..hum.."&field3="..tempout.."")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)

Re: post to thingspeak.com

PostPosted: Wed Sep 23, 2015 11:37 pm
by bbx10node
184.106.153.149 might be an old or wrong IP address. Connect to "api.thingspeak.com" instead.

If this fails, try "ping api.thingspeak.com" and use the IP address it returns. This is less desirable since IP addresses frequently change so it may work today but fail in the future.

Re: post to thingspeak.com

PostPosted: Thu Sep 24, 2015 4:25 am
by jankop
It's the wrong time sequence of commands in your program. First, you have to wait for a connection, send, and you can not close the connection before everything is sent.
There is a functional sketch.

Code: Select all--    Tested with Lua NodeMCU 0.9.6 (nodemcu_float_0.9.6-dev_20150704.bin)
--    Minimal period for data send to api.thingspeak.com is 15s
--****************************************************************
   ssid="yourSSID"    -- your router SSID
        pass="yourPassword"   -- your router password
   wifi.setmode(wifi.STATION)
   wifi.sta.config(ssid,pass,1)

   apiKey="yourAPIwriteKey" -- set your thingspeak.com key
   tempin=21.3   
   hum=52.5   
   tempout=18.7

-- send data to https://api.thingspeak.com
conn = net.createConnection(net.TCP, 0)
conn:connect(80,'api.thingspeak.com') -- This row is good, but only for newer firmware
--conn:connect(80,'184.106.153.149') -- This is worse, but it also works well with the older firmware.
conn:on("connection",
   function(conn)
   print("Connection!")
   conn:send('GET /update?key='..apiKey..
   '&headers=false'..
   '&field1='..tempin..
   '&field2='..hum..
   '&field3='..tempout..
   ' HTTP/1.1\r\n'..
   'Host: api.thingspeak.com\r\nAccept: */*\r\n'..
   'User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n\r\n')
   end)
conn:on("sent",
   function(conn)
   print("Sent!")
   --conn:close() -- You can enable this row for skip thingspeak.com answer
   end)
conn:on("receive",
   function(conn, payload)
   print("Receive!")
   print(payload)
   conn:close()
   end)
conn:on("disconnection",
   function(conn)
   print("Disconnection!")
   end)