Sorry, I was not clear in my question. I have a simple html file based on your post about servo control showing temperature. I would like to add the current time to the web page. In my sketch, am using Serial.print(Time.timeStr());.
This works in the serial monitor.
What do i need to put into the html file to display Time.timeStr?
Great job @bko I am new to spark but your simple method of showing how to expose the variables for the web means I will have some sweet user interfaces done in short order. Thanks for taking the time to share. I will share my own tutorial once I have completed my āweb thermostatā
@bko I took your concept and built on it a bit. I am not using a button I am instead polling for data. I found that if I polled faster then 1 minute the data was VERY unreliable lots of 408 errors as the API just crapped out. That is a bit unfortunate since 1 minute data updates is a bit slow for my tastes.
I am monitoring all kinds of āneat stuffā but not displaying most of it currently.
My project is a spark core thermostat with built in live weather data and graphing. Nowhere near done my next step is to send commands BACK to the spark ( not sure how to do that just yet pointers welcome ).
Here is a screenshot of the working system on my smart phone, all data you see is live.
Thanks I will read up on publish. Right now it seems even when I am doing a 1minute interval on api reads it still will not update every time without fail. More ātinkeringā to be done
@Herner, Iām trying to get a thermostat for my garage heater together. You phone interface is very nicely laid out! What are you using to build the app? Are you planning on sharing code publicly? Iāve got a working 2 car garage door monitor/controller working with functions, maybe I can help?
I am using HTML5 to build it all and will likely share with the community ALL of the code since I have received such great help here myself. I saw your garage door opener and was thinking I need to do that for my house
Lets say you want to monitor data that you want to poll and still be respectful of our cloud neighbors by not polling so frequently, but need to be able to retrieve that data monitored during the time your not āactivelyā looking at it.
For instance a flow sensor monitoring water over time. I may not need to look at it every 10 seconds, but when I DO look at it, I may want that accurate(ish) data.
Is it possible to āstoreā that real-time data collected and then poll it in periodically?
Iām very new to this so please forgive me if Im not being clear.
There are several services on the internet who can do just that for you. They can poll, log, and visualize your data. Google App Scripts has been used for this, although itās being slightly problematic lately. Ubidots also seems to be a popular option. Atomiot is a solution designed by one of our forum members, and works nicely with the Spark ecosystem, definitely check that out.
Try searching the forums for the solutions Iāve mentioned above and Iām sure plenty of options will pop up. Should you require any further help, please do let us know, and weāll see what we can do to help you out.
i just came across this thread and Iām looking forward to working through this, but I had a question on the safety issue which hasnāt been covered much here, other than to avoid it. If we just have our photon sitting on the internet and monitoring a temperature or recording whether a motor is running (my application) etc. Is there really an issue with someone getting access to your data? I understand that theoretically we shouldnāt allow people to get to our data, but in reality Iām not sure I see the issue in this situation. Does anyone have a thought???
It is not so much your data that you need to be worried about and indeed many folks use Particle.publish() to put data out of the cloud on the public channel. Similarly a public dashboard that read your deviceās variables and show them would be fine.
The problem is that your access token is like your username/password and can be used to reprogram or do other things to your Particle devices. You should protect that access token like you would a username/password. If a token is compromised, it can be cancelled, but the problems are best avoided.
So this example does not try to hide that token since you cannot easily do that in a short HTML example where someone could āView Sourceā on your web page, but there are lots of good ways to keep it secure including a PHP setup on a web server or a more sophisticated app that creates a new throw-away token when you log in.
Hi BKO -
Thanks so much for getting back to me. I appreciate your helping to explain the issues. Iām trying to just get a basic system setup and looking at all the options for doing that. From what you are saying here it sounds like if I donāt expose the access token then I should be OK. And the example you have here just has the access token hardcoded into the html. I understand that can be a bit more cumbersome to deal with for a simple example like this. I will chase that down with the information you have already put into this (thanks again!).
As a different approach, do you know if there is a simple way to grab the data that the photons put out in variables (or with the publish command) using visual studio? Iām much more comfortable programming in visual studio and have many programs that I have put together in visual basic. Iām wanting to learn all the different systems, but when you are learning 6 things at once it is often easier if you can be comfortable with at least one of the steps
I am assuming you mean writing in Visual C using the Visual Studio IDE here. Yes, any programming language and IDE that can do HTTPS web requests can access the Particle cloud. The cloud just provides a RESTful interface to send and get data--you can access that interface via the provided URL scheme from any kind of program you care to write.
For some programming languages and environments, like NodeJS, there is a Particle-supplied library that makes that super easy, but it is not too hard in any language.
I am a newbie to HTML programming.I am trying to read a particle variable with HTML file as shown in the tutorial. When i run the HTML file, just the waiting for data is being displayed. And there is nothing again. I checked on api.particle.io and the variable value is being displayed correctly.
A couple of things look like problems in your code:
You are calling Particle.publish() every 500ms while the publishing rate limit is one per second with a burst of up to four allowed as long as you average one per second. After four publishes, you code will become bogged down by the rate limiting.
You donāt show the part of the HTML that holds the variable data that has the IDās of ātempā and ātstampā. Those are required since the start() function looks for those exact element names to update. @moors7: these disappeared due to lack of formatting, just fixed that.
You know that you have to replace the <<deviceid_mine>> and <<accesstoken_mine>> with the actual hex values special for you. You can get these in the web IDE among many other places.
What happens if you run the tutorial as written? Does that work for you?
Regarding the suggestions,
1.) Yes, i am putting the access token and device ID values in var deviceID and var accessToken.
2.) I am not able to understand what your suggestion 2 is.āYou donāt show the part of the HTML that holds the variable data that has the IDās of ātempā and ātstampā. Those are required since the start() function looks for those exact element names to update.ā
3) I have changed the code to call Partile.publish every 2 secs and even then the result is same.
I have checked the particle.api and these are the returend JSON values
Coincidentally, Iāve also got a device with a temp variable. I copied your code, entered my own Accesstoken and DeviceID and it works flawlessly. Are you sure youāre replacing them correctly? They should look something like:
var deviceID = "50ff6c061234567896580487";
var accessToken = "72922955de86ac1234567894e49e7e0cc403c090";