Install Node-Red in Win10

Posted on Updated on

  • Install node.js – I am using version 5.4.0. Download

Once installed in command window

npm install -g --unsafe-perm node-red

then install dashboard

npm install node-red-dashboard

 

Done

Flow – Set Date and Time

Posted on Updated on

I needed for a user interface using dashboard to change the system date and time for only offline use.

Set time zone using raspi-config to UTC

and then:

[{"id":"36c3d555.2f131a","type":"ui_form","z":"95a3d4b7.c328c","name":"","label":"Time Setting","group":"d5789dec.c52058","order":0,"width":0,"height":0,"options":[{"label":"Fri Nov 4 17:50:00 UTC 2016","value":"Time","type":"text","required":true}],"formValue":{"Time":""},"payload":"","topic":"","x":116.5,"y":66,"wires":[["a31c7a2b.05a228"]]},{"id":"b1edd921.e154a","type":"exec","z":"95a3d4b7.c328c","command":"sudo date","addpay":true,"append":"","useSpawn":"","timer":"","name":"Set Time","x":431.5,"y":64.5,"wires":[["23954dbb.e1b912"],[],[]]},{"id":"d0531b60.f27f88","type":"ui_text","z":"95a3d4b7.c328c","group":"d5789dec.c52058","order":0,"width":"0","height":"0","name":"","label":"Actual System Date and Time","format":"{{msg.payload}}","layout":"row-spread","x":505.5,"y":157,"wires":[]},{"id":"9f79c87.21b00b8","type":"inject","z":"95a3d4b7.c328c","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"x":122.5,"y":153,"wires":[["5f3c74a9.0f72bc"]]},{"id":"23954dbb.e1b912","type":"debug","z":"95a3d4b7.c328c","name":"","active":true,"console":"false","complete":"false","x":608.5,"y":64,"wires":[]},{"id":"5f3c74a9.0f72bc","type":"function","z":"95a3d4b7.c328c","name":"","func":"// Create a Date object from the payload\nvar date = new Date(msg.payload);\n// Change the payload to be a formatted Date string\nmsg.payload = date.toString();\n// Return the message so it can be sent on\nreturn msg;","outputs":1,"noerr":0,"x":278.5,"y":156,"wires":[["d0531b60.f27f88"]]},{"id":"e2689290.c72908","type":"function","z":"95a3d4b7.c328c","name":"","func":"msg.payload = \"-\" +'\"' + \"s \" + msg.payload + '\"';\nreturn msg;\n\n//sudo date -\"s Fri Nov 4 17:50:00 UTC 2016\"","outputs":1,"noerr":0,"x":274.5,"y":273,"wires":[["26012639.277dea"]]},{"id":"adb62291.b5d0c8","type":"inject","z":"95a3d4b7.c328c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126.5,"y":273,"wires":[["e2689290.c72908"]]},{"id":"26012639.277dea","type":"debug","z":"95a3d4b7.c328c","name":"","active":true,"console":"false","complete":"false","x":458.5,"y":274,"wires":[]},{"id":"a31c7a2b.05a228","type":"function","z":"95a3d4b7.c328c","name":"","func":"var strtime = msg.payload.Time;\nmsg.payload = \"-\" +'\"' + \"s \" + strtime + '\"';\nreturn msg;","outputs":1,"noerr":0,"x":276,"y":65,"wires":[["26012639.277dea","b1edd921.e154a"]]},{"id":"d5789dec.c52058","type":"ui_group","z":"","name":"Time Setting","tab":"862d2fe5.7ba4a","order":1,"disp":false,"width":"16"},{"id":"862d2fe5.7ba4a","type":"ui_tab","z":"","name":"Setting","icon":"dashboard","order":2}]

Flow – Send command

Posted on Updated on

A couple of commands example.

 [{"id":"9d317c9d.94ec4","type":"inject","z":"95dd8c1e.9f45b8","name":"shutdown!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":254,"y":105,"wires":[["47b1920.62f3bf"]]},{"id":"47b1920.62f3bf","type":"exec","z":"95dd8c1e.9f45b8","command":"sudo poweroff #","append":"","useSpawn":"","name":"turn off Pi","x":428,"y":104,"wires":[[],[],[]]},{"id":"28150e2f.21a1ea","type":"inject","z":"95dd8c1e.9f45b8","name":"reboot!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":255,"y":188,"wires":[["f211e72e.571f78"]]},{"id":"f211e72e.571f78","type":"exec","z":"95dd8c1e.9f45b8","command":"sudo reboot #","addpay":false,"append":"","useSpawn":"","timer":"","name":"Reboot Pi","x":430,"y":193,"wires":[[],[],[]]},{"id":"9fdf1eef.cd09f","type":"inject","z":"95dd8c1e.9f45b8","name":"video off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":248,"y":277,"wires":[["d5a598dc.db0b9"]]},{"id":"d5a598dc.db0b9","type":"exec","z":"95dd8c1e.9f45b8","command":"vcgencmd display_power 0","addpay":false,"append":"","useSpawn":"","timer":"","name":"Video Off","x":431,"y":279,"wires":[[],[],[]]}]

screen-shot-2016-11-05-at-7-21-04-am

Flow – Dashboard Reset Chart

Posted on Updated on

If you like to reset the content of a graph in Node-Red dashboard, use this method.

[{"id":"69c51240.a88d64","type":"ui_chart","z":"95dd8c1e.9f45b8","name":"","group":"982d5ce1.fdf228","order":4,"width":"5","height":"2","label":"","chartType":"line","legend":"false","xformat":"%H:%M","interpolate":"linear","nodata":"","ymin":"-40","ymax":"80","removeOlder":1,"removeOlderUnit":"3600","x":521,"y":119,"wires":[[],[]]},{"id":"9475826e.ef16e","type":"json","z":"95dd8c1e.9f45b8","name":"","x":348.5,"y":121,"wires":[["69c51240.a88d64"]]},{"id":"72de27fd.a64e08","type":"inject","z":"95dd8c1e.9f45b8","name":"Reset","topic":"","payload":"[ { \"key\": \"Data\", \"values\": []}]","payloadType":"str","repeat":"","crontab":"","once":false,"x":185.5,"y":121,"wires":[["9475826e.ef16e"]]},{"id":"982d5ce1.fdf228","type":"ui_group","name":"Group 1","tab":"6db0468b.7fc248","order":1,"disp":true,"width":6},{"id":"6db0468b.7fc248","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":3}]

screen-shot-2016-11-04-at-11-34-54-pm

Raspberry Pi 3 Jessie – LAMP SERVER

Posted on Updated on

Steps to setup LAMP on Raspberry Pi3 Jessie

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo service apache2 restart

or

sudo /etc/init.d/apache2 restart

test by entering the IP address in a browser

sudo apt-get install mysql-server php5-mysql

When installing MySQL you will be asked for a root password.

sudo service apache2 restart
sudo apt-get install phpmyadmin

Raspbian Jessie Mosquitto Broker

Posted on

Install Mosquitto Broker in few steps (Raspbian Jessie)

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

sudo apt-key add mosquitto-repo.gpg.key

rm mosquitto-repo.gpg.key

cd /etc/apt/sources.list.d/

sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

sudo apt-get update
sudo apt-get install mosquitto

Nextion Raspberry Pi UI

Posted on Updated on

A quick project to connect a Nextion HMI to Raspberry Pi and get some text displayed. (Or whatever goes through your mind)

nextion_hmi_320x240

I am using a Chinese version (I am in China!) of 2.8″ 320×240 device.

  • The Nextion project

I made a simple screen with 4 text field to receive data form the RPI.

The text field are named: t0, t1, t2, t3.

nextion_project

Here is the project file (download and rename it as rpi_hmi.HMI)

downlod rpi_hmi.HMI

pi3_gpio

Connect + 5 VDC to pin 2

Connect GND to pin 6

Connect Rx to pin 8

Connect Tx to pin 10

  • To send data to the screen I am using my favorite application: Node-Red.

From Node-Red it is possible to run commands and send them to the serial port.

Before that we should make sure that the serial port is available.

If RPI 2, read this post.

If RPI 3, read this post.

In PRI 3 , to use ttyAMA0 it is necessary to stop the bluetooth.

To send data to the Nextion, we should format them like:

t0.txt=, 0x22, text to send, 0x22, 0xFF, 0xFF, 0xFF

Here is the Node-Red flow.

[{"id":"244f48cf.81b92","type":"inject","z":"7a00aa0e.a9b7d4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":128.5,"y":136,"wires":[["e0180d8.3c9047"]]},{"id":"e0180d8.3c9047","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":288.5,"y":135,"wires":[["858c79ee.44437"]]},{"id":"858c79ee.44437","type":"serial out","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":502.5,"y":134,"wires":[]},{"id":"2466d4ba.b7759c","type":"serial-port","z":"7a00aa0e.a9b7d4","serialport":"/dev/ttyAMA0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"100","bin":"bin","out":"time","addchar":false}]

Another flow to display the CPU temperature

[{"id":"244f48cf.81b92","type":"inject","z":"7a00aa0e.a9b7d4","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":128.5,"y":136,"wires":[["e0180d8.3c9047","3c8c3ccb.ea114c","ef39e89d.a084d"]]},{"id":"e0180d8.3c9047","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t0.txt=\";\ns_text = \"Hello World\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":288.5,"y":135,"wires":[["858c79ee.44437"]]},{"id":"858c79ee.44437","type":"serial out","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":636.5,"y":138,"wires":[]},{"id":"8d36ba49.d16358","type":"serial in","z":"7a00aa0e.a9b7d4","name":"","serial":"2466d4ba.b7759c","x":112.5,"y":414,"wires":[["9057e978.8b3c"]]},{"id":"9057e978.8b3c","type":"debug","z":"7a00aa0e.a9b7d4","name":"","active":true,"console":"false","complete":"false","x":398.5,"y":417,"wires":[]},{"id":"3c8c3ccb.ea114c","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t1.txt=\";\ns_text = \"Line 2\";\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":289,"y":199,"wires":[["858c79ee.44437"]]},{"id":"ef39e89d.a084d","type":"exec","z":"7a00aa0e.a9b7d4","command":"vcgencmd measure_temp","addpay":false,"append":"","useSpawn":false,"timer":"","name":"measure temp","x":347,"y":295,"wires":[["b985e249.4f6ff8"],[],[]]},{"id":"b985e249.4f6ff8","type":"function","z":"7a00aa0e.a9b7d4","name":"","func":"s_object = \"t2.txt=\";\ns_text = msg.payload;\nvar arr = [];\nfor (var i = 0, l = s_object.length; i < l; i ++) {\n    var ascii = s_object.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\nfor (var i = 0, l = s_text.length; i < l; i ++) {\n    var ascii = s_text.charCodeAt(i);\n    arr.push(ascii);\n}\narr.push(0x22);\narr.push(0xFF);\narr.push(0xFF);\narr.push(0xFF);\nmsg.payload = new Buffer(arr);\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":286,"wires":[["858c79ee.44437"]]},{"id":"2466d4ba.b7759c","type":"serial-port","z":"7a00aa0e.a9b7d4","serialport":"/dev/ttyAMA0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"500","bin":"bin","out":"time","addchar":false}]

Enjoy.

Virtual Serial Port over IP

Posted on

If you like to connect from your Windows environment to your newly ESP8266 ESP-Link, you may use the very good software from Tibbo to create a virtual serial port.

http://tibbo.com/support/downloads/tdst.html

Download the version corresponding to your system (x32 or x64).

Install the package.

Open Tibbo VSP Manager and Add a port

step_0

Set the properties of the port as following to creat a TCP connection to the ESP8266 flashed with ESP-Link. The IP at the bottom is the IP address of the ESP82266!

Once done, a virtual port will be created in the COM section of the Device Manager.

For testing, use the serial console of Arduino IDE. (One of my temperature logger is sending data through the ESP8266).

From the console of the ESP-Link

step_7

 

I don’t know if it is possible to use the serial port to program an arduino that way but I know that the control lines could be changed from the setting. Let’s see, I will give it a try later.

Enjoy.

 

CNC -Makercam

Posted on Updated on

Just a quick note: I have been testing makercam (http://www.makercam.com) as a replacement for Gcode tools extension in Inkscape to generate the gcode for my CNC controlled by Mach3.

Works great and the stuff takes care of the tool offset, things I never managed automatically with Gcode tool.

I will add a couple of tips from my first test soon.

 

Steps to flash ESP-Link to ESP8266 4 Mbyte (ESP12)

Posted on Updated on

Just few words about flashing ESP-Link on ESP8266 (I posted first working on the ESP01 but gave it up. It bugs a lot. I use now a 4 Mbyte version.)

Yesterday I was looking (bit lazy) to make an ESP8266 TCP / Serial bridge in order to remote control one of my Nextion screen with Node-red (development and testing only).

While browsing I found out ESP-Link. Very nice tool. (Pity, I found that too late)

So, in few steps, to flash it you need to:

  • Download ESP-Link flasher software

http://www.espressif.com/en/support/download/other-tools?keys=&field_type_tid%5B%5D=14

  • Download firmware

https://github.com/jeelabs/esp-link/releases/tag/v2.2.3

  • Get the hardware info of the ESP

To do so, connect to the ESP the tool ESP flash download tool and press start.

step_1

Once the button start is pressed, you will get the hardware details in the Detected Info window.

step_2

Use the info for setting the right flash size and also the right address for flashing.

  • Use this setting for flashing:

step_3

  • Connect to the ESP8266 AP
  • In your browser go to: 192.168.4.1
  • You are good to go for more setting from the webpage

If you like to erase the flah, use the method of Patrik @

Completely format or erase ESP8266 flash memory