Particle Photon Configuration with Tinker Firmware | 赛普拉斯半导体
Particle Photon Configuration with Tinker Firmware
In the last article I wrote about using a CY3280 MBR3 Shield on a WICED WiFI 943907AEVAL1F development kit at the GE MegaHackathon. In the next article I will show you the WICED HTTP firmware that I wrote to connect to the Particle Photon which they were using (I have written about Particle Photon before). Obviously, I like Particle Photon because it is a WICED 43362 WiFi Radio. In this article, I am going to show you how to get a Particle Photon going with the Tinker firmware. Then test it with the iOS app, the web console and finally using CURL. The CURL is just a mechanism to send HTTP Posts to the Tinker firmware, exactly what I will do in the next article on the WICED development kit.
Configure the Particle Photon
When you get a fresh Particle Photon out of the box you need to get it introduced to your WiFi network, and attached to your console. To do this, start by going to setup.particle.io and following the process.
Testing with iPhone App
One you have “claimed” your Particle Photon and it is connected to the network, then you can talk to it with the Particle iOS app. Here is what it looked like when I started the App on my phone. You can see the device called “iotexpert-example” (remember that is what I named it from above). The “Elkhorn_creek” Photon is the one that I wrote about in this article.
Although the console says that I have the Tinker Firmware on the app, I wanted to make sure, so I use the iOS App to re-flash the Tinker Firmware. You can do this by clicking the new device, then press the little “…” at the top right of the screen. Finally click “Reflash Tinker”. It is awesome how fast that happens.
Once I am sure about the version of the Tinker firmware, I test to make sure that things are working correctly. First I click on “D7”
Which brings up this screen where you can select digitalRead and digitalWrite.
Then when you press the button it will switch from high to low and vice versa.
You can also call the API directly by pressing “inspect” then “Data”
Particle Photon Console
In addition to using the iOS App, you can also interact with the Photon using the console.
When I click on the “iotexpert-example” it brings up this screen where I can run the Tinker firmware functions. In this case I ran “digitialwrite” with “D7,HIGH” which turns on the LED on the Photon.
Testing the Particle Photon with CURL
The Particle Cloud exposes an API which lets you send Restful API requests to specific devices. The Unix tool CURL lets me type command line requests (which I will mimic in the next Article using WICED). The first command that I send is and HTTP GET which will return a JSON document that describes the configuration on my Photon.
curl https://api.particle.io/v1/devices/iotexpert-example?access_token=1311f67269d6
You can see the device name etc in the JSON below. It also shows that the Tinker firmware has four function built into it.
{
"id":"2a001b000347353137323334",
"name":"iotexpert-example",
"last_app":null,
"last_ip_address":"69.23.226.142",
"last_heard":"2017-09-17T15:38:56.406Z",
"product_id":6,
"connected":true,
"platform_id":6,
"cellular":false,
"notes":null,
"status":"normal",
"current_build_target":"0.5.3",
"variables":{
},
"functions":[
"digitalread",
"digitalwrite",
"analogread",
"analogwrite"
]
}
Then I can send a HTTP POST using Curl to turn on the D7 LED.
curl https://api.spark.io/v1/devices/2a001b000347354/digitalwrite -d access_token=1311f67269d66b -d params=D7,HIGH
You can see the Blue LED right next to D7 turns on.
Particle Photon Tinker App
I wondered where the Tinker App API was documented? It turns out that the App is available in Particle library. You can search by typing “tinker”.
The section of code that matters is here. The function takes a “String” and parses it. It demands that the 2nd character be a PIN number between 0 and 7. The first character be a capital “D”. Then you need to have a “HIGH” (in caps) or a “LOW” (in caps)
/*******************************************************************************
* Function Name : tinkerDigitalWrite
* Description : Sets the specified pin HIGH or LOW
* Input : Pin and value
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int tinkerDigitalWrite(String command)
{
bool value = 0;
//convert ascii to integer
int pinNumber = command.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber< 0 || pinNumber >7) return -1;
if(command.substring(3,7) == "HIGH") value = 1;
else if(command.substring(3,6) == "LOW") value = 0;
else return -2;
if(command.startsWith("D"))
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, value);
return 1;
}
else if(command.startsWith("A"))
{
pinMode(pinNumber+10, OUTPUT);
digitalWrite(pinNumber+10, value);
return 1;
}
else return -3;
}
In order to access the digitalwrite function via the network, they publish it (and some others).
/***
* All the based tinker functions are registered. You can add you own code.
***/
// This #include statement was automatically added by the Spark IDE.
#include "Tinker.h"
void setup() {
//Register all the Tinker functions
Spark.function("digitalread", tinkerDigitalRead);
Spark.function("digitalwrite", tinkerDigitalWrite);
Spark.function("analogread", tinkerAnalogRead);
Spark.function("analogwrite", tinkerAnalogWrite);
}
void loop() {
}
When I first thought about the Tinker firmware I thought that it must be reasonably complex. But it is not because it takes advantage of the Particle cloud functionality. All in all what they did is very elegant and simple..
Now that it looks like my Particle Photon is working, in the next article I will show you WICED firmware to read the CapSense buttons and then Turn On/Off the LED on the Photon.
本网站上的所有内容和材料均“按原样”提供。赛普拉斯半导体公司及其各个供应商对这些材料用于任何用途的适用性不作陈述,并且对关于这些材料的所有担保和条件概不负责,包括但不限于有关适销性、针对特定用途之适用性、权利和不侵犯任何第三方知识产权的所有暗示担保和条件。赛普拉斯半导体公司不授予任何明示或暗示的许可(无论是以默许方式或是任何其他方式)。使用本网站上的信息可能需要第三方的许可,或赛普拉斯半导体公司的许可。
本网站上的内容可能包含或必须遵守关于使用的特定准则或限制。所有帖子和使用本网站上的内容都必须遵守本网站的条款与条件;使用这些内容的第三方必须同意遵守任何限制或准则,并遵守本网站的条款与条件。赛普拉斯半导体公司及其供应商保留随时对内容和材料、产品、计划和服务进行纠正、删除、修改、增强、改进或其他变更,或者移动或终止任何内容、产品、计划或服务的权利,恕不另行通知。
Comments
Thank you for sharing. This is really informative post, I will definitely share this with my friends. I am writer, currently providing write my paper service for student.
Thanks for taking time for writing on particle photon configuration with tinker firmware. This will sure help developers who are looking for such kind of tutorial how to configure particle photon with easy steps. By after providing college assignments help to university students at Quality Dissertation under the guidance of expert writers, I love to read tutorial & guidance, tips on various subjects which are important for everyone in daily life as well as professional.
Great tutorial!
Word meaning, definition Spanish dictionary online
Router 192.168.1.1 help
I read your entire article and I genuinely like it. like this
I think this is an informative post and it is very useful and knowledgeable. Voyance par téléphone gratuite.
A great article on particle photon. I remember when I took my first modern physic subject at new mexico state university, it was awesome. Now I am doing other things in life but still keep an eye on the latest developments in this field. Some of my other interests now include online gemstones & beads