Reading the Spark Core temperature sensors

User avatar
Marcel
Posts: 8
Joined: Tue Jun 06, 2017 6:55 pm
My devices: iPad pro
Flag: Netherlands
Contact:

Reading the Spark Core temperature sensors

Post by Marcel » Sat Jun 10, 2017 6:45 pm

Hi,

Today I wrote my first little program in smart BASIC. I had already a VBA version and translated this into smart BASIC. It was very easy due to the simplicity of smart BASIC. It does nothing else than reading the Spark Core server to which the Spark Core is connected. Each Core has a core ID and each Core has an Access Token. These are personal and you must keep them secret. The data transmission is secure at https level and you need to register your device first.

The Spark Core
SparkCore.png
SparkCore.png (271.76 KiB) Viewed 1213 times

Code: Select all

COREID$ = "********************"
ACCTKN$ = "*******************************"
temp_no$ = "temp1"
URL$ = "https://api.******/devices/"&COREID$&"/"&temp_no$&"?access_token="&ACCTKN$
HTTP URL$ GET t$
PRINT t$
The code above returns the next JSON string.

{"cmd":"VarReturn","name":"temp2","result":32.19065934065935,"coreInfo":{"last_app":"","last_heard":"2017-06-10T17:35:34.992Z","connected":true,"last_handshake_at":"2017-06-10T17:00:20.923Z","deviceID":"****************","product_id":0}}

Spark Core Program
The Spark Core has a program that reads the temperatuire sensors. The 2 temperature sensors are LM335Z types. The datasheet is here. The output of the sensor is fed to an analog input, which just reads the voltage of the output.

WEBIDE.JPG
WEBIDE.JPG (50.21 KiB) Viewed 1213 times
I have a VBA macro program running in Excel and it collects this JSON string and extracts the temperature. It puts the temperature value with the date in a table and the data is shown in a graph.

SparkCoreExcelTemp.PNG
SparkCoreExcelTemp.PNG (88.58 KiB) Viewed 1213 times
So you can ask for the temperature where ever you've put such a device at home. This device can also recieve information from the Spark Server. If you create an App with smart BASIC and you want to switch someting on like a LED light you can do that. This wil be my next goal.

I think smart BASIC will become a powerful App to produce home appliance applications for domotics on iPads and iPhones. Now with smart BASIC it is very simple to write your own Apps.

Namaste.
Last edited by Marcel on Mon Jun 12, 2017 5:18 pm, edited 2 times in total.

User avatar
GeorgeMcGinn
Posts: 419
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Reading the Spark Core temperature sensors

Post by GeorgeMcGinn » Sun Jun 11, 2017 7:26 am

Hi Marcel,

I had originally looked into SmartBASIC for use in sensors and HiJack devices, but found that it wasn't robust enough.

I had an idea that if I where to send data to a webserver via a WIFI card, that I could read the data and perform the graphing.

However, I find what you have done very intriguing.

I've been using techBASIC because it has all the classes and you can directly access the sensors using the sensor's address and get realtime feed. Yes, if you use an Arduino Board, you need to write your own OS to interface to.

I have started to look at how you are accomplishing this with SmartBASIC, and I have some questions, which I am researching, but I am working on too many projects and my not get my answers as quick as I'd like.

I see in the SB code that you are using ****'s to mask codes you do not want to see, such as the API. What is the API provider, and how do I apply for my own API key? The same with the COREID and the ACCTKN values.

I don't expect your to provide us yours, although we do, such as the weatherwize and other programs we do provide our API keys and tell people how to apply for their own.

Also, for the JSON file (not JASON), it seems to me that you need to constantly issue the HTTP link to refresh with new data. Have close does that get you to receiving realtime data?

For accessing and processing realtime data down to intervals of 1/10th of a second, techBASIC is a different type of language specifically designed for sensors and IoT.

But there are some devices I am building now that I do not need to monitor the data in realtime, and what you are doing is what I am looking for. I have another group of sensors I am looking to use on a golf course, but I do not need to get data realtime. I can download the day's data and run it through a program that analyzes the data from various sensors.

In order to monitor it realtime, I most likely will need to keep an iPad or iPhone collecting and storing the data as it occurs, and I may be able to back up all the data to a website, but the chance of having my equipment stolen it too great to even consider realtime monitoring. I can collect realtime data and store it, the retrieve it all later.

Thanks for your post.This is a field that I am very interested in, and the ability to use SB gives me many more options to sensor design and data collection.

George.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
http://georgemcginn.wordpress.com
http://cosmologyandspace.wordpress.com

User avatar
Marcel
Posts: 8
Joined: Tue Jun 06, 2017 6:55 pm
My devices: iPad pro
Flag: Netherlands
Contact:

Re: Reading the Spark Core temperature sensors

Post by Marcel » Sun Jun 11, 2017 9:25 am

Hello George,

A few years ago I found some guys on the internet who started with the Spark Core. Now Spark is rebranded as Particle. You can read at https://www.particle.io/ more about it. You can buy these devices at Particle and you can register them at their site. You access the devices via their web API services. The codes I changed in **** are personal and if you make them public others can claim your device so you must not publish them. The device has an unique ID and Access Token. Read the docs they will explain everything.

I work only in the Particle Build console in a web application in Google Chrome. You can program the device in c and check and compile your code. The code is compiled at their servers and send back to your device when you want to flash it. Nice thing is that you can update your program over the web, flashing the device with your new program. In the beginning it was very unstable but it is getting better and better.

For realtime data I just set the interval to 10 sec. Did not test 1/10 sec as you mentioned. I do not know if there is a speed limit. If the device collects new values it is send to the Particle server and then I read them. This goes with the HTTP GET.

I just finished an example with HTTP POST for controlling 2 LED's via the WEB. It work very fast, almost direct.

The goal was to test if I could use smart BASIC for accessing the Spark Core and it does that in a very simple way. Now I can program my own interfaces and can proceed with my domotics projects.

I hope I answered your questions.

User avatar
GeorgeMcGinn
Posts: 419
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Reading the Spark Core temperature sensors

Post by GeorgeMcGinn » Tue Jun 13, 2017 5:52 am

Hi Marcel,

Thanks for the info and I will get me signed up. I understand that you don't want others changing your code for the device.

As i work on the projects I working now (Climate change box that monitors 20 sensors, a Geiger counter, and for observational astronomy, I am designing an optical sensor to produce a spectograph for redshift, element detections, and if the telescope is large enough, exoplanet detection) among other simpler sensors so I can get some practical work with it (I need to either repair or buy a new MAC next month so I can create the apps to test my devices).

Let's keep in touch, as I would love to see how far we can take SmartBASIC in using sensors and the data from them.

We may not be able to use it to gather realtime data like with techBASIC, but SmartBASIC under the right circumstances can and should be able to handle and analyze the data produced.

Mr. K. This is just a suggestion for possible future use, but if we can get something where SB as it is written now can interface with IoT, and there is enough programmers who want to take SB to that level, maybe we can create a sub-forum. It isn't needed now, and it may not be need for awhile, I just wanted to float the idea by you. I'm not expecting a decision on it, but I just wanted to make this suggestion. Then we can post .io code and other (Raspberry PI, even Python as I am looking at it in controlling sensors and it has the libraries already standard in its current release, according to it manual).

This could be exciting to see what we can accomplish. And maybe I can now put my dedicated webserver to good use here as well!
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
http://georgemcginn.wordpress.com
http://cosmologyandspace.wordpress.com

User avatar
Mr. Kibernetik
Site Admin
Posts: 4415
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPad, iPhone, MacBook
Location: Russia
Flag: Russia

Re: Reading the Spark Core temperature sensors

Post by Mr. Kibernetik » Tue Jun 13, 2017 6:29 am

Yes, why not.

User avatar
Marcel
Posts: 8
Joined: Tue Jun 06, 2017 6:55 pm
My devices: iPad pro
Flag: Netherlands
Contact:

Re: Reading the Spark Core temperature sensors

Post by Marcel » Tue Jun 13, 2017 5:49 pm

Hi George,
I understand that you don't want others changing your code for the device.
That is correct, if I would publish my Core ID and Access token my device would become useless. However the code I published can be used if you have such a device.

smart BASIC at the moment is very useful just with the HTTP functions now. You can get data from a Spark Core or Photon. If you run a webserver on a Rasberry Pi than you can do the same http interfacing. You can store data to cloud data services such as google data or other providers.

The only thing I would like to have in smart BASIC would be IP Sockets to do some low level UDP/TCP/IP and have more control to the network and ports without the need of a HTTP-webserver. I do not know if the iPad OS does allow that but that would be a killer. I could access my devices by WiFi and much more such as PLC's in a more direct way without the use of a provider like Particle.
Let's keep in touch, as I would love to see how far we can take SmartBASIC in using sensors and the data from them.
Yes, why not. Electronics is beautiful and it becomes more beautiful if it can be accessed by smart BASIC on an iPad. smart BASIC is already a beautiful Gem, we need just to polish it. :D

Corrected some typos.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4415
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPad, iPhone, MacBook
Location: Russia
Flag: Russia

Re: Reading the Spark Core temperature sensors

Post by Mr. Kibernetik » Thu Jun 15, 2017 4:32 am

Marcel wrote:
Tue Jun 13, 2017 5:49 pm
The only thing I would like to have in smart BASIC would be IP Sockets to do some low level UDP/TCP/IP and have more control to the network and ports without the need of a HTTP-webserver.
Thank you for suggestion.

User avatar
GeorgeMcGinn
Posts: 419
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Reading the Spark Core temperature sensors

Post by GeorgeMcGinn » Fri Jun 16, 2017 3:51 pm

Since SB can run CGI Scripts, why not let the script access the lower level (IP Sockets) for you?

It would be a work-a-round, but with a properly written script, SB can have a two-way conversation by calling the script with the necessary parms to send Input and receive output when the script returns.

George.
Mr. Kibernetik wrote:
Thu Jun 15, 2017 4:32 am
Marcel wrote:
Tue Jun 13, 2017 5:49 pm
The only thing I would like to have in smart BASIC would be IP Sockets to do some low level UDP/TCP/IP and have more control to the network and ports without the need of a HTTP-webserver.
Thank you for suggestion.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
http://georgemcginn.wordpress.com
http://cosmologyandspace.wordpress.com

User avatar
Marcel
Posts: 8
Joined: Tue Jun 06, 2017 6:55 pm
My devices: iPad pro
Flag: Netherlands
Contact:

Re: Reading the Spark Core temperature sensors

Post by Marcel » Fri Jun 16, 2017 7:31 pm

I want to eliminate the webserver and doing just tcp/ip to other devices such as a PLC.

User avatar
GeorgeMcGinn
Posts: 419
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro
IMac
Location: Venice, FL
Flag: United States of America
Contact:

Re: Reading the Spark Core temperature sensors

Post by GeorgeMcGinn » Fri Jun 16, 2017 9:31 pm

Then you will need a language that allows direct access to TCP/IP, UDP, etc.

TechBASIC is what I use (they have a comm. class, i.e. Comm.openTCPIP(1, "169.254.1.1", 2000)) or use ObjectiveBASIC or ObjectiveC. SWIFT may also have direct access to the comm class.

Otherwise, to access the comm classes in SmartBASIC, unless there is an undocumented feature, you need to use the HTTP protocol statements.

George.
Marcel wrote:
Fri Jun 16, 2017 7:31 pm
I want to eliminate the webserver and doing just tcp/ip to other devices such as a PLC.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)
http://georgemcginn.wordpress.com
http://cosmologyandspace.wordpress.com

Post Reply