Summary
Test on Samsung ARTIK 530 connect ARTIK Cloud by using Node-RED, use ARTIK 530 Switch to control the ARTIK 530 LED lighting, go through the cloud (ARTIK 530 switch –> ARTIK Cloud Switch –> ARTIK Cloud Rule engine –> ARTIK530 LED Light), with successful result.
ARTIK Cloud control ARTIK 530 LED
Create ARTIK Cloud Rules
Follow this Link to create cloud rules.
if ARTIK Cloud Switch state is true, then send to ARTIK Cloud Light the action setOn
if ARTIK Cloud Switch state is false, then send to send to ARTIK Cloud Light the action setOff.
Node-RED create logic
Start Node-Red,
[root@artik ~]# node-red &
[1] 2258
[root@artik ~]#
[root@artik ~]#
[root@artik ~]# 29 Jun 21:56:56 - [info]
Welcome to Node-RED
===================
29 Jun 21:56:56 - [info] Node-RED version: v0.16.2
29 Jun 21:56:56 - [info] Node.js version: v4.7.3
29 Jun 21:56:56 - [info] Linux 4.4.19-0530GC0F-44F-01Q3 arm LE
29 Jun 21:56:58 - [info] Loading palette nodes
29 Jun 21:57:07 - [warn] ------------------------------------------------------
29 Jun 21:57:07 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
29 Jun 21:57:07 - [warn] ------------------------------------------------------
29 Jun 21:57:07 - [info] Settings file : /root/.node-red/settings.js
29 Jun 21:57:07 - [info] User directory : /root/.node-red
29 Jun 21:57:07 - [info] Flows file : /root/.node-red/flows_artik.json
29 Jun 21:57:07 - [info] Server now running at http://127.0.0.1:1880/
29 Jun 21:57:07 - [info] Starting flows
29 Jun 21:57:07 - [info] Started flows
Below pic shows the overall Node-RED flow,
ARTIK Cloud IN receives actions from ARTIK Cloud, the Device ID and Device token are from ARTIK Cloud Light. It will receive ARTIK Cloud Light action and output to next node.
The debug node will output the debugging information in the debug panel.
The ‘pmw function’ will process the input from ARTIK Cloud Light input, and process before pass to pwm node, pic shows as,
var actions = msg.actions;
var action = actions[0].name;
if (action === 'setOn') {
msg.payload = {
"state": 1,
"dutyCycle": 500000000,
"peroid": 1000000000,
};
} else if (action === 'setOff') {
msg.payload = {
"state": 0
};
}
return msg;
pwm node is as below, ARTIK 530 and ARTIK 730 only have PWM 0.
The ‘Control LED Function’ is the function to process the ARTIK Cloud Light input data before it passes to ‘ARTIK530_BlueLED’ node.
var actions = msg.actions;
var action = actions[0].name;
var state = global.get('state')||0;
if (action === 'setOn') {
global.set('state',1);
} else if (action === 'setOff') {
global.set('state',0);
}
msg.payload = {};
msg.payload.state = state;
return msg;
‘ARTIK530_BlueLED’ configure as below,
The testing result is as below video shows, basically whenever there is ARTIK Cloud Light action coming in, it will trigger the process function to control the PWM 0 and ARTIK 530 Blue LED light on, tested with direct action on the ARTIK Cloud Device.
src="https://www.youtube.com/embed/C_zgCeePQAQ" allowfullscreen="" width="854" height="480">You can also control by following procedure, the ARTIK 530 Switch –> ARTIK Cloud Switch –> ARTIK Cloud Rule engine –> ARTIK 530 Cloud Light –> ARTIK Node-RED in –> PWM 0 and Blue LED light on, all are working properly.
src="https://www.youtube.com/embed/zp6R0QRrHn4" allowfullscreen="" width="854" height="480">ARTIK Cloud Temp Sensor upload data to ARTIK Cloud
Below test is to input the Temp Sensor to the ARTIK Cloud, as I don’t have the hardware Temp Sensor with the ARTIK 530, so I simulate the Temp Sensor by using the Node-RED function input and upload the data to ARTIK Cloud temp sensor.
The Node-RED flow shows as below,
‘timestamp’ is as below, trigger the function every 2 seconds.
‘Temp Function’ is as below, output to debugging node and ‘ARTIK Cloud Temp Sensor’ node.
var voltage_raw = Math.random();
var voltage = voltage_raw * 2 * 0.439453125;
//Converting from 10mv per degree with 500mV offset
var temperatureC = (voltage - 0.5) * 100 ;
var temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
msg.payload = {
"temperature": temperatureF
};
return msg;
The debugging node is as below,
The ‘ARTIK Cloud Temp Sensor’ node is as below, the device ID and device token is from ARTIK Cloud Temp Sensor.
The testing result will show the temperature data will be uploaded to ARTIK Cloud, as the upload interval is 2 seconds, you will see a very clear view of waveform (fluctuate temperature) on the CHART output.
Video shows the chart result.
src="https://www.youtube.com/embed/eTeNLT_D3Pk" allowfullscreen="" width="854" height="480">Reference
Blog: Samsung ARTIK 530 test on Node-RED
Blog: Samsung ARTIK 530 cloud connectivity test
https://developer.artik.io, Introduction to Node-RED