Blog

March 02, 2015 | Python , Electronics |

A Python script to talk to the Spark Core

I have been playing around with the Spark Core and am very impressed with the built-in software support from Spark. This is a quick project that uses Python to talk to the Spark Core using the Spark cloud API. I also wanted the Spark Core to sent notifications to my program, and for this I am using Spark.publish() and Server Sent Events (SSE).

Here is a sample run of the program. (You can get the access token from Spark Build IDE.)

$ python talk_spark.py --at XXXX_ACCESS_TOKEN --list
[{u'connected': True, u'last_heard': u'2015-02-26T02:17:22.450Z', u'last_app': None, u'id': u'xxxxxxx', u'name': u'yyyy'}]

$ python talk_spark.py --at XXXX_ACCESS_TOKEN --listen
Notification: Yo 4 at 2015-02-26T01:59:02.272Z
Notification: Yo 5 at 2015-02-26T01:59:07.278Z
Notification: Yo 6 at 2015-02-26T01:59:12.281Z
^Cexiting.

You can find the source files for the project here, which has the Python code, as well as a simple Spark Core program for testing notifications. I look forward to playing with the Spark Photon next.


Consulting

Need help with a hardware project or product? Drop us an email at info@electronut.in. We offer consulting services on AVR and Nordic nRF BLE - hardware design, firmware development, prototyping, PCB design/assembly, sourcing and manufacturing. We can help you bring your product to market!


Bluey nRF52 BLE IoT dev board

bluey
Check out our Bluey nRF52 BLE development board with built-in Accelerometer/Gyroscope, Temperature/Humidity and Ambient Light sensors. It's a fabulous tool to learn Nordic nRF52 BLE programming and explore IoT technologies.

Questions/Comments

We love hearing from our readers. Email us at info@electronut.in for questions or comments on this article. If you found this article useful, please support us by buying some of our hardware products.


Please sign up for updates

Once in a while, we will send you an email update on the latest Electronut Labs projects and products. Your email address will never be shared or abused, ever.

2016 Electronut Labs. All rights reserved.