Controlling LED's with the Spark Core over the web.

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

Controlling LED's with the Spark Core over the web.

Post by Marcel »

Hi,

My goal was to check if I could use smart BASIC to control my Spark Core IoT device. Here I show the smart BASIC code and the Spark Core c code that does the job. I've connected 2 leds to the Spark Core and will control them via the iPad and smart BASIC.

LED.JPG
LED.JPG (137.97 KiB) Viewed 2953 times

Below you see the Particle WEB IDE and the c code which is flashed to memory inside the Spark Core. The Spark is just trapped in a loop but when there is a matching API request for the leds the function ledControl() is run.

WEBIDE2.JPG
WEBIDE2.JPG (57.57 KiB) Viewed 2953 times

I created with help of the smart BASIC documentation the next BASIC code.

Code: Select all

COREID$ = "*******************"
ACCTKN$ = "********************"

led1 = 1
IF led1 = 1 THEN
	send_cmd$ = "params=l1,HIGH"
ELSE
	send_cmd$ = "params=l1,LOW"
ENDIF
URL$ = "https://api.*****/devices/" & COREID$ & "/led?access_token=" & ACCTKN$
h$(1) = "content-type:application/x-www-form-urlencoded; charset=UTF-8"
HTTP URL$ HEADER h$ POST send_cmd$
PRINT HTTP_RESPONSE$()
PRINT "HTTP HEADER: " & HTTP_HEADER$()
PRINT "HTTP STATUS: " & HTTP_STATUS()
PRINT "HTTP ERRORS: " & HTTP_ERROR$()
END
The result of this code is that the LED which is at the OFF state is switched ON. Below you see the HEADER and STATUS information after the request has been sent.

{"id":"************************","last_app":"","connected":true,"return_value":1}
HTTP HEADER: Connection: keep-alive
Date: Sun, 11 Jun 2017 08:19:34 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 81
Server: nginx
Access-Control-Allow-Origin: *
HTTP STATUS: 200
HTTP ERRORS:

I hope you wil get inpired to use smart BASIC in combination with the IoT devices like the Spark Core or Photon.

Namasté
Last edited by Marcel on Sun Jul 15, 2018 7:57 am, edited 1 time in total.

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

Re: Controlling LED's with the Spark Core over the web.

Post by Mr. Kibernetik »

Very interesting!

Post Reply