Particle.io

From makernexuswiki
Revision as of 15:12, 22 October 2021 by BobG (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Unfortunately their community pages are long, long conversations that are not trimmed up and easy to read. Once you find a gem of information, post it here.

Particle.io (formerly Spark.io)

This is an "Arduino-like" processor. So far it has run all my Arduino code without a problem. We even brought over some other libraries and they worked. This platform easily connects to WiFi and Particle.io runs a cloud based service that makes talking to your core easy. Once the Particle Core is on WiFi then you can compile your code for it using either a web browser or their Particle Dev application on your local computer. In either case your software is compiled in the Particle Cloud and then pushed down to your Particle Core. This is beautiful. There is no need to be anywhere near your Particle Core when you send it new software.

The Particle firmware contains libraries that let you expose a local variable on your core, or a local function. Then these can be called from any web browser. Thus you can interact with your software on your core from anywhere in the world. Lastly, they offer Spark.publish which your software can call to send short messages through the Particle Cloud service (free) to anywhere. Your own server could monitor the Spark Cloud for alerts from your core(s). IFTTT.com offers a channel for Spark. I've had my core publish events to the cloud that IFTTT picks up and turns into SMS messages to my phone. IFTTT could also add events to a Google Docs spreadsheet.

The original Spark Core cost $35 and was configured via an app on a smart phone. In June 2015 they will ship the new Photon which costs $20 and I believe will be configured via its own WiFi hotspot (like the way Chromecast is configured). In October 2015 they will ship the new Electron which will offer cellular data connectivity for $3/month. In October they are also planning to release a solar power kit for the Electron. With all of this you will be able to put an Electron on the top of any local mountain and interact with it forever. Wow.

Photon

String concatenation

We found a bit of code that would compile and run on the Spark Core, but not on the Photon. Here's the workaround:

  • original code: bufferReadout += Time.timeStr(index);
  • revised code: bufferReadout += Time.timeStr(index).c_str();

Javascript

I wanted to interact with my Spark Core through the Spark Cloud. I wanted to do it without having an active web server, so I wrote code to do it in Javascript (a nasty language to work with). The page I wrote will allow you to log on to your Spark account, get information from your core, and then send messages back and forth. To use this you only need the Javascript code to run in your browser. The current version of my code will read the Spark Cloud to get a list of variables and methods that your core firmware exports. It also monitors your core for any Publish events it sends. You can run this from my web site, or go there and download all the code so you can modify it and run it anywhere you want. The download includes a simple sample firmware app to run on your core. But the web site also works with the factory installed firmware. http://shrimpware.com/SIS

Flashing Green does not connect

After much fooling around and Google searching I found that the Spark Core would not connect to my WiFi because I was using WEP encryption. Once I switched to WAP it worked fine. My Spark Core was working fine for weeks sitting next to me in my office (20 feet from the WiFi access point). Then one day it started dropping the WiFi connection and could not recover it. After a lot of searching I decided to move it closer to my WiFi access point (8 feet) and it worked reliably again. Weeks later I moved it back to my office and it worked fine for a few days; then it did not. My assessment: In my office the WiFi signal is strong enough most times, but occasionally someone/thing near by our house starts transmitting (perhaps the police station?) in a way that prevents my Spark Core from connecting when it is 20 feet from the WiFi access point.

Creating an App to Communicate with a Particle Device

Particle provides a REST API (to the Particle Cloud) that allows an app to (1) read out the value of a global variable on the Particle device, at any time, and (2) call a function on the Particle device, also at any time. We have used this API capability to create Android apps in MIT App Inventor 2 that communicate with our Photon and Argon based projects. Complete details can be found at:

 https://github.com/TeamPracticalProjects/MIT-App-Inventor-Particle-Photon-test

Particle on-line documentation can be found at:

 https://docs.particle.io/reference/device-os/firmware/#cloud-functions

The Particle Cloud functions "Particle.variable()" and "Particle.function()" make it particularly easy to create apps that interact with your Particle-based project. MIT App Inventor 2 is a block-based programming language that is very easy to learn and use, and yet is capable of producing very useful apps. Information about MIT App Inventor 2 can be found at:

 http://ai2.appinventor.mit.edu/

MIT App Inventor 2 is currently limited to developing apps for Android. However, MIT is well along in the development of support for iOS. MIT App Inventor 2 is entirely web based (no IDE to install) and is entirely free to use.

The Particle Cloud functions "Particle.publish()" and "Particle.subscribe()" are also particularly useful. The pair can be used for secure device-device communication via the Particle Cloud. Particle.publish() can also be used to fire off Particle Webhooks that can trigger Web APIs for third party cloud services, e.g. Google Sheets. Particle.subscribe() can then be used to receive webhook responses from third party cloud services. We have used these capabilities extensively in the Maker Nexus RFID access control system; for details see:

 https://github.com/makernexus/MN_ACL

We have recently learned how to use Google Apps Scripts, in conjunction with Particle.publish() and Particle webhooks, to flexibly log data to Google sheets. We have also learned how to use Google Apps Scripts, in conjunction with Particle.publish() and Particle webhooks, to send e-mail and SMS mobile texts for alarms/alerts from Particle-based projects. Detailed documentation can be found at:

 https://github.com/TeamPracticalProjects/Connectivity_Tools_with_Particle_Devices/blob/main/TPP_Connectivity_Tools_Technical_Description.pdf