We have moved at community.getvera.com

Author Topic: ThingSpeak  (Read 28562 times)

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #45 on: July 25, 2018, 05:09:42 am »
Hi

I thought I would give Thingspeak a go and can see some example code here, which always help (thanks for sharing).

Would someone be able to share more about the end to end process for Thingspeak, the channel they set up, their code and the resulting graph ?

Attached is a screenshot of their Channel set up page, which in the example I want to do - which is to track the temperature of one room - I assume I would just create one Channel, with one field called CurrentTemperature ? Is that it ?

Are things like date/time required or is that provided by Thingspeak when the information if posted via the api to their site?
« Last Edit: July 25, 2018, 06:10:54 am by parkerc »

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1050
  • Karma: +27/-31
Re: ThingSpeak
« Reply #46 on: July 25, 2018, 09:09:54 am »
I would be curious to know too. AltUI has a data provider to easily link thingspeak but I'm no longer get using AltUI. It might have already been mentioned in this thread though.

Sent from my VS995 using Tapatalk


Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #47 on: July 25, 2018, 05:26:57 pm »
Hi @tomtcom

So far so good for me.

Ive created a channel called House Temps and listed out my Vera temperature sensors as the fields - I only have a few sensors at the moment, so have created some dummy temp entries as placeholders, resulting in a channel with 7 fields.

The code being used for this, which is associated with a scene thats set to run every 30mins is as follows.

Code: [Select]
local http = require("socket.http")
http.TIMEOUT = 5

local conservatorytemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 304)
local kitchentemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 179)
local hallwaytemp = 20
local livingroomtemp = 20
local frontroomtemp = 20
local leantotemp = 20
local outsidetemp = 20

local API_KEY = "put_your_api_key_here"

    local urlTable = {
        "http://api.thingspeak.com/update?key=", API_KEY,
        "&field1=", conservatorytemp,
        "&field2=", kitchentemp,
        "&field3=", hallwaytemp,
        "&field4=", livingroomtemp,
        "&field5=", frontroomtemp,
        "&field6=", leantotemp,       
        "&field7=", outsidetemp
    }

    local urlStr = table.concat(urlTable)
    local result, status = http.request(urlStr, "run=run")
 
« Last Edit: July 25, 2018, 05:47:53 pm by parkerc »

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1050
  • Karma: +27/-31
Re: ThingSpeak
« Reply #48 on: July 26, 2018, 04:01:02 pm »
Hi @tomtcom

So far so good for me.

Ive created a channel called House Temps and listed out my Vera temperature sensors as the fields - I only have a few sensors at the moment, so have created some dummy temp entries as placeholders, resulting in a channel with 7 fields.

The code being used for this, which is associated with a scene thats set to run every 30mins is as follows.

Thanks @parkerc, I'll give this a shot.

I thought it would be a bit more difficult then this but since I paid for the mobile thinkspeak app and had an account a while back I remember now I had the API keys. I'll need to brush up on what else I can do for value conversions. Using datamine2 you can only add a multiplier to data and not divide. So if I wanted to show memory usage from the system monitor plugin it would have to stay as 145,000 kb instead of making it an MB value. But I'll research that separate of this.

Thanks again for the code, appreciate it.

Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #49 on: July 26, 2018, 04:10:45 pm »
No problem @tomtcom, glad to help (that code was just pieced together from this thread so kudos to the others)

When you have progressed and created your channel and feed, feel free to post the code you used and examples of the graphed results it?ll be good to see how you end up using it.

I didnt realise there was a mobile app either - is this it?

Quote
Things Speak by Barna Szternak https://itunes.apple.com/gb/app/things-speak/id1191667398?mt=8
« Last Edit: July 26, 2018, 04:14:26 pm by parkerc »

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1050
  • Karma: +27/-31
Re: ThingSpeak
« Reply #50 on: July 26, 2018, 04:35:20 pm »
No problem @tomtcom, glad to help (that code was just pieced together from this thread so kudos to the others)

When you have progressed and created your channel and feed, feel free to post the code you used and examples of the graphed results it?ll be good to see how you end up using it.

I didnt realise there was a mobile app either - is this it?

Quote
Things Speak by Barna Szternak https://itunes.apple.com/gb/app/things-speak/id1191667398?mt=8

Will do!

I am using this one for Android: https://play.google.com/store/apps/details?id=com.cinetica_tech.thingview.full

After I went to their site, I see no links for mobile apps so maybe both are just third party.


Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #51 on: July 26, 2018, 05:54:26 pm »
Another potentially helpful bit of code (which i found online) creates a sort of dashboard for your Thingspeak graphs. Paste it into a file with a html file extension and you?ll see what I mean.

Code: [Select]
<html>
<head>
<title>Data Collection Dashboard</title>
</head>
<body>
<table border=2 bordercolor="#0000FF">
<tr><td colspan="2">
<h1 align="center" color="#00FFFF">Data Collection Dashboard</h1>
</td></tr>
<tr><td>
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/320695/charts/1?bgcolor=%23ffffff&color=%23F62020&dynamic=true&results=800&type=line&update=15"></iframe>
</td>
<td><iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/apps/matlab_visualizations/166526?color=%23FFFFFF&dynamic=true"></iframe>
</td></tr>
<tr><td>
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/12397/charts/2?results=720&dynamic=true&update=15"></iframe>
</td>
<td>
<iframe width="300" style="border: 1px solid #cccccc;" src="https://thingspeak.com/apps/matlab_visualizations/171403"></iframe>
<h3>Links</h3>
<a href="https://www.google.com">Google</a><br>
<a href="https://www.Mathworks.com">Mathworks</a><br>
<a href="https://en.wikipedia.org/wiki/Cleve_Moler">Wikipedia</a>
</td>
</html>

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1050
  • Karma: +27/-31
Re: ThingSpeak
« Reply #52 on: July 26, 2018, 08:51:31 pm »
Thanks @parkerc. I was able to successfully get luup restarts from System Monitor plugin however something might not be working right due to the variable content. I'll need time to tweak.

In addition, my app on the phone isn't pulling it in even with the correct user api key checked.

I only have a manual on-demand scene until I get things working right but thank you. If this works out after tweaking I will probably remove DataMine2.

Code: [Select]
local http = require("socket.http")
http.TIMEOUT = 5

local luuprestart = luup.variable_get("urn:cd-jackson-com:serviceId:SystemMonitor", "systemLuupRestartTime", 188)

local API_KEY = "write_api_key"

    local urlTable = {
        "http://api.thingspeak.com/update?key=", API_KEY,
        "&field1=", luuprestart
    }

    local urlStr = table.concat(urlTable)
    local result, status = http.request(urlStr, "run=run")


Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #53 on: July 26, 2018, 09:05:22 pm »
Just an idea - so not fully thought through yet but seeing as the date/time is marked/captured by Thingspeak when you send information to them.

Rather than try to send that date/time variable maybe consider putting this code within your lua start up and have it just send something basic like the number 1 (As lua start up is run upon each luup restart - therefore the act of that code running would be confirmation that a luup restart has occurred)

Thingspeak would then in turn just plot those 1s on a graph.
« Last Edit: July 26, 2018, 09:10:04 pm by parkerc »

Offline tomtcom

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1050
  • Karma: +27/-31
Re: ThingSpeak
« Reply #54 on: July 26, 2018, 09:16:14 pm »
Just an idea - so not fully thought through yet but seeing as the date/time is marked/captured by Thingspeak when you send information to them.

Rather than try to send that date/time variable maybe consider putting this code within your lua start up and have it just send something basic like the number 1 (As lua start up is run upon each luup restart - therefore the act of that code running would be confirmation that a luup restart has occurred)

Thingspeak would then in turn just plot those 1s on a graph.
I've thought of that over the years reading this forum. I need more play time though.

To show what I want to achieve this is data mine 2 using imperihome app.

So I want to achieve this and thingspeak doesn't require port forwarding to view it off wifi.(https://uploads.tapatalk-cdn.com/20180727/0dff08ae4fe1cce9d87f20d1f376b28e.jpg)

Sent from my VS995 using Tapatalk


Offline parkerc

  • Beta Testers
  • Sr. Hero Member
  • *****
  • Posts: 2479
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: ThingSpeak
« Reply #55 on: July 26, 2018, 09:28:32 pm »
That looks do-able, and the way I have suggested would certainly plot all the luup restarts with a dot and a date time along a graph.

To have it spike or increment as your current chart suggests - that would need some coding - but potentially you could do something that counts (numbers) the restarts during the day sending incrementing numbers and then reset to zero at say midnight .

That way you can see how many restarts youve had each day and when they occurred.

Have a think - have a play :)

Offline korttoma

  • Hero Member
  • *****
  • Posts: 729
  • Karma: +26/-5
Re: ThingSpeak
« Reply #56 on: January 17, 2019, 02:59:55 am »
Anyone here still using ThingSpeak?
All my channels stopped working 16h ago, anyone else having problems?

Tried to renew API key and even clearing a channel but still no luck...
« Last Edit: January 17, 2019, 03:05:33 am by korttoma »
- Tomas

Offline korttoma

  • Hero Member
  • *****
  • Posts: 729
  • Karma: +26/-5
Re: ThingSpeak
« Reply #57 on: January 17, 2019, 10:20:46 am »
Strange, rebooted my 4G modem when I got home an it started working again. Internet was working fine!? Or so I thought.
- Tomas