|
Forum Index : Microcontroller and PC projects : Pi-cromite: IOT with ThingSpeak
| Author | Message | ||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10565 |
This example shows how to log data to Thingspeak with the Pi-cromite. It uses the Pi-cromite's TCP client capability. The code measures the temperature every 30 seconds and then uploads the current temperature and the running maximum and minimum to Thingspeak. I was surprised how easy this was option explicit option default none Dim m$,s$, n$, api_key$="my Write API Key" Dim float current,maxtemp=-1000.0,mintemp=1000.0 m$="GET http://api.thingspeak.com/update?api_key="+api_key$+"&field1=" Do TCP client "184.106.153.149",80 'fixed address for Thingspeak HTTP current=DS18B20(33) If current>maxtemp Then maxtemp=current If current<mintemp Then mintemp=current s$=m$+Str$(current)+"&field2="+Str$(maxtemp)+"&field3="+Str$(mintemp) s$=s$+Chr$(13)+Chr$(10) Print s$; TCP send s$ Pause 1000 TCP receive n$ 'clear the TCP receive buffer TCP close Pause 29000 Loop You can see the cold UK temperature here |
||||
| kg4pid Regular Member Joined: 08/03/2015 Location: United StatesPosts: 50 |
I'm trying to follow your code but I don't see where you provide a login/user name along with a password. In looking at the web page I see a 'channel id'. Why do I not see this in the code? While it looks simple, there must more code/setting that are somewhere else. Max |
||||
| Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
It's probably in the first line below, api_key$= Uses an api key instead of username/pwd by the look of it. |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10565 |
There isn't otherwise I would have included it. The Write API Key is the username/password and channel id combined on ThingSpeak which is why I didn't include my key |
||||
| Azure Guru Joined: 09/11/2017 Location: AustraliaPosts: 446 |
I thought you were going to share |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |