G6EJD / ESP32-ESP8266-How-to-read-THINGSPEAK-Channel

Reading THINGSPEAK JSON formatted responses to GET request
Other
14 stars 7 forks source link

connection failed #1

Closed consolacion closed 6 years ago

consolacion commented 7 years ago

Sadly, the connection (ESP8266) kept failing. As your "API_Key" looks more like a channel ID than a key, I tried it with both a channel ID as well as with the API Read Key, but no prevail

G6EJD commented 7 years ago

The channel I use is public and others have been able to read and write to it. I'll have a look at what's going wrong if anything. Try putting some diagnostic prints in your code copy.

consolacion commented 7 years ago

Thanks. I have tried that channel, I tried a channel of my own, no luck. Just to make sure I loaded one of my own thingspeak (upload) programs.. that can connect without problems. Will put some diagnostics in it but the 'connection failed' is more or less the first diagnostic encountered :-)

Update: apparently I needed a bit more patience. After initial fail(s), it started to retrieve data after a while. Tnx

G6EJD commented 7 years ago

Strange, I have just re-programmed a new Wemos D1 Mini and it connects first time and the response was this: {"channel":{"id":320098,"name":"Test Channel","latitude":"0.0","longitude":"0.0","field1":"Pressure","field2":"Temperature","field3":"Humidity","created_at":"2017-08-21T13:22:12Z","updated_at":"2017-08-28T09:53:29Z","last_entry_id":85},"feeds":[{"created_at":"2017-08-26T22:15:06Z","entry_id":81,"field1":"40"},{"created_at":"2017-08-26T22:15:29Z","entry_id":82,"field1":"41"},{"created_at":"2017-08-26T22:15:52Z","entry_id":83,"field1":"42"},{"created_at":"2017-08-26T22:17:53Z","entry_id":84,"field1":"43"},{"created_at":"2017-08-26T22:18:16Z","entry_id":85,"field1":"44"}]}

Channel id: 320098 Name: Test Channel Readings last updated at: 2017-08-28T09:53:29Z Field1 entry number [81] had a value of: 40 Field1 entry number [82] had a value of: 41 Field1 entry number [83] had a value of: 42 Field1 entry number [84] had a value of: 43 Field1 entry number [85] had a value of: 44

You should be able to read your own channels noting of course your keys will be different and have you enabled Public access on your channels? When the ESP8266 connects the Thing speak server has no credentials to check other than channel number e.g. 820098

G6EJD commented 7 years ago

If I use a bogus key I get (expected) this: {"status":"404","error":"Not Found"}

Channel id: Name: Readings last updated at: Field1 entry number [] had a value of: Field1 entry number [] had a value of: Field1 entry number [] had a value of: Field1 entry number [] had a value of: Field1 entry number [] had a value of:

consolacion commented 7 years ago

Thanks, Well I can read yr and my own channel but it just doesnt happen on the first time. I standard get a 'connection failed' but if I wait I guess 1 or 2 times the 'delay(60000)' it eventually starts to read. using a Lolin board but that shldnt make any difference, so it works, just not on the first try

G6EJD commented 7 years ago

Interesting mine does work first time, can't understand why other than hardware differences. But I have been reading about subtle API changes and it suggests both API Read Key and Channel are required for Private channel reading, not for PUBLIC though, but it works either way, new code version upload with a #define to switch between partial (channel # only) and full (channel # and API Read key) request modes.

consolacion commented 7 years ago

odd indeed. I just tried on a Wemos D1 mini, just to be sure and had the same. It happens with your channel and with my public channel. Maybe just some setting in my LAN