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.
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.
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
{"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é