[gallery columns="1" size="full" ids="3233"]

Particle has a complete open source IoT hardware and platform. Since 2013, it has first launched the CORTEX M3 IoT development board based on TI CC3000.

The current series are:

  • Particle Core

  • Particle Photon

  • Particle Electron


Among them, Particle Electron is a development board based on 3G networking. Both Core and Photon use wifi as a connection.

Particles, whether firmware, software or even hardware, are currently open source, and developers can download and customize their own IoT hardware and platforms:

  • Particle Github

  • Particle docs

  • Particle Store


First, to integrate Photon with the QNAP NAS, you need to install the relevant services first:

Step 1: Install Container Station

Step 2: Install Node-Red through Container Station (original Node-Red preset does not support Particle module, please install this version)

Step 3: After the installation is complete, you can directly open the Node-Red management page, as following (http://your-nas-ip:1880, the default port is 1880)

[gallery columns="1" size="full" ids="3234"]

Step 4: After successfully opening Node-Red, you can find the node module related to Particle. Currently supports three categories, event, function and variable

[gallery columns="1" size="full" ids="3235"]

Step 5: Next, before setting up Particle Photon, you need to install the relevant setting environment (flash through the command line, you can refer to this method).

# how to install the particle-cli

$ npm install -g particle-cli

$ particle login

Step 6: Update Photon (Note: you need to enter DFU mode)

How to enter DFU mode

  1. Find two buttons from the device and press the RESET and SETUP buttons simultaneously

  2. Release the RESET button first and keep pressing SETUP

  3. When the light has changed to flashing "yellow light", the representative device has entered DFU mode.


$ particle update

[gallery size="full" columns="1" ids="3236"]

After the update is successful, you can query the current version through the following instructions.

$particle identify

Your device id is 2xx02b000xxxxxxxxx30xx3x

Your system firmware version is 0.5.2

Step 7: The first time you take Photon, you need to set up WiFi first, and connect to Particle Cloud (if you need to connect Photon directly through your phone, you can refer to this method).

Link USB to start Photon, the first use will continue to flash "blue light"

$ particle setup

Login Particle Cloud → Set up your wireless network → Name your Photon → Set up Photon successfully

Once the wireless network is set up, you can find that the original flashing blue light will turn into a breathing light, indicating that the Particle Cloud has been successfully connected.

[gallery columns="1" size="full" ids="3237"]

Step 8: List the current Particle device. The following icon shows the Jarvis-NAS-Photon that has just been set. The 2d0xxxxxxxxxxx037 is the device id. It can be recorded first and will be used later.

$particle list

[gallery columns="1" size="full" ids="3238"]

After setting up the Particle device and NAS, start the serial device and Node-Red.

First, log in to Particle Build, there are two things to do here:

  1. Put in the test source code, test event, function and variable.

  2. Obtain an access token that accesses the relevant API permissions, and then use it in Node-Red.


Let's first put the original code of the test below into the Photon just set up. The function is mainly to send the LED status through the event, to obtain the control LED status through the function and the current LED status.
Int ledStatus = 0;

Int ledPin = D7;



// LED function

Int getLedStatus(String cmd);

Int setLedStatus(String cmd);



Void setup() {

pinMode(ledPin, OUTPUT);



// Set a variable let user can get LED status.

Particle.variable("ledstatus", ledStatus);



// Set function let user can call it.

Particle.function("getLedStatus", getLedStatus);

Particle.function("setLedStatus", setLedStatus);

}



Void loop() {

ledStatus = digitalRead(ledPin);



// Publish event to Particle cloud.

Particle.publish("ledstatus", String(ledStatus));



Delay(5000);

}



Int getLedStatus(String cmd){

ledStatus = digitalRead(ledPin);



Return ledStatus;

}



Int setLedStatus(String cmd){

If(cmd == "true"){

digitalWrite(ledPin, HIGH);

}else{

digitalWrite(ledPin, LOW);

}

}

After attaching the code, you can perform the burning action, as following:

[gallery columns="1" size="full" ids="3239"]

By the way, during the burning process, the LED status of the device will be bright yellow and blue, then flash and connect, and finally converted into a breathing light, indicating successful burning.

Now that the settings on the device have been completed, the next step is to get the access token to access the relevant API permissions, and then use it in Node-Red, as following:

[gallery columns="1" size="full" ids="3240"]

 

After getting the access token, put this token into the Particle node provided by Node-Red.

First create a new Particle Cloud config, then fill in the relevant information, for example: Name, Device ID, Event

[gallery columns="1" size="full" ids="3241"]

 

After the completion, as following, fill in the Event name "ledstatus" just set up, and then connect the output node to the Particle node.

[gallery columns="1" size="full" ids="3243"]

The result of the output event....

[gallery columns="1" size="full" ids="3244"]

In addition to obtaining device-related information through web pages, Particle can also obtain status information of current devices through REST API.

 

# GET

Https://api.particle.io/v1/devices/2d002bxxxxxxxxxx03037?access_token=e2bd9e98axxxxxxxxxxf1970916xxxxxxx

[gallery columns="1" size="full" ids="3245"]

Get ledstatus variable status

# GET

Https://api.particle.io/v1/devices/2d002bxxxxxxxxxx03037/ledstatus?access_token=e2bd9e98axxxxxxxxxxf1970916xxxxxxx

[gallery columns="1" size="full" ids="3246"]

Get the current LED status, through the Particle function
# POST

Curl https://api.particle.io/v1/devices/2d002b00xxxxxxxxx53xx037/getLedStatus \

-d access_token=e2bd9e98xxxxxxxxxxxxx19709xxxxxxxxxx6c92c

{

"id": "2d002b000a47353235303037",

"last_app": "",

"connected": true,

"return_value": 1

}

Set LED status setLedStatus
# POST, args=true -> LED On; args=false -> LED off

Curl https://api.particle.io/v1/devices/2d002b00xxxxxxxxx53xx037/setLedStatus \

-d access_token=e2bd9e98xxxxxxxxxxxxx19709xxxxxxxxxx6c92c \

-d "args=true"



{

"id": "2d002b000a47353235303037",

"last_app": "",

"connected": true,

"return_value": 536959528

}

In addition to the REST API method and control device, it can also be controlled by Node-Red to control the LED switch through the inject node.

[gallery columns="1" size="full" ids="3247"]

It's not difficult to control the device through Node-Red. If you don't want to spend money on the cloud platform, and just NAS supports docker, it's not difficult to get a simple IoT service.

It will then be introduced for more Particle related applications, including:

  1. Build your own Particle Cloud

  2. Integrate water quality sensing device to create your own fish tank monitoring system

  3. Introduce Particle Electron with 3G module






Synchronized at: I’m RD.

 
arrow
arrow
    全站熱搜

    tttt 發表在 痞客邦 留言(0) 人氣()