Store data from an IOT device through the TTN network to a database with Node-Red and MQTT

This is a quick post on how to store data from an IOT device through The Things Network to a (mysql) database.

  • Install Node-Red:

sudo apt-get install node-red

  • Install Node-Red-Mysql:

npm install node-red-node-mysql

  • Start node-red and add an MQTT node and set the following parameters:


Connection, server: staging.thethingsnetwork.org
Security, username: your <App EUI> from the TTN application and password (click the link 'learn how to get data from this app')

  • Set the Topic to: <your App EUI>/devices/+/up
  • Add a ‘function’ node and set the code to:


data = (msg.payload);
var m = {
topic : "INSERT INTO `yourtable` (`data`) VALUES ('" + data + "');"
};
return m;

  • Add a mysql node and set the parameters
  • Link the nodes together. The result should look something like this:

node-red

You can also use the TTN node instead of the MQTT node:

https://www.npmjs.com/package/node-red-contrib-ttn

 

ESP8266 Arduino

This setup worked for me when using an ESP8266 with Arduino:

esp8266

Pay attention to set CH_PD to VCC +3.3v, this is not mentioned in the first link.

The sequence I used to program the ESP8266 is:
1. Apply the external power supply to the ESP8266
2. Connect a USB cable between the USB-UART and the USB port
3. Ground the GPIO0 pin
4. Momentarily ground the RST pin
5. Click the IDE’s upload button

Sources:
Youtube ESP8266 Arduino IDE HowTo
https://github.com/esp8266/Arduino
http://www.esp8266.com/viewtopic.php?p=30793#p30793

 

 

 

How to emulate with an Android-x86 image in VirtualBox

Get the VirtualBox IP address with ipconfig (in my case 192.168.56)

Kill the running server:
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb kill-server <enter>

And reconnect:
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb connect 192.168.56.1:5555 <enter>

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
connected to 192.168.56.1:5555

More info here.

DIY Arduino robot car with remote control

Here is a video of my homemade Arduino robot car and remote control.

Used components on robot car:
– Arduino Mega 2560
– L298N Dual H Bridge
– Bluetooth HC-05 (see other video for remote control with an Android phone)
– nRF24L01 radio module for communication
– Some bright LEDs
– C1008 pnp transistor for switching the leds
– Tower pro servo for steering
– DC motor from an old cd-player
– Aluminium and plexiglas for the frame
– Plastic Tire Wheels
– IIC/I2C/TWI 1602 Serial Blue Backlight LCD
– Some resistors and capacitor
– Bearings
– Breadboard and wires ofcourse
– 10v battery

Remote control:
– Arduino Nano (clone)
– Nokia 5110 lcd display
– nRF24L01 radio module
– Some resistors and capacitor
– Pushbuttons, on/off switch
– Prototype pcb
– 9v battery