Introduction: Wireless Vibration and Temperature Sensor Data to MySQL Using Node-RED
Introducing NCD’s Long Range IoT Industrial wireless vibration and temperature sensor, boasting up to a 2-mile range the use of a wireless mesh networking structure. Incorporating a precision 16-bit vibration and temperature sensor, this device transmits incredibly accurate vibration and temperature records at consumer-described durations.
Step 1: Hardware and Software Required
Step 2: Setting Up XAMPP
XAMPP is most prevailing, free an open-source cross-platform which is one solution to run your web services. XAMPP is developed by ApacheFriends which released in May 2002. XAMPP Stands for Cross-Platform(X), Apache(A), MySQL(M) also Sometimes (M) refers to MariaDB, PHP(P) and Pearl(P).
XAMPP allows you to work on a local server and test local copies of websites using PHP code and MySQL databases. Once XAMPP is active, you can access your local copy with a browser using an URL like http://localhost/ or http://localhost/
Downloading and Installing
XAMPP Go to XAMPP web site and download the installer based on your operating system. Installation should be similar to a normal software installation you do in your operating system. When installing, there would be an option to select whether you want to run Apache and MySQL as services. If you chose it, Apache and MySQL will start at system boot-up which may not need if your computer is tight with memory resources or if you are not doing PHP development frequently. You can change these settings after installation.
Step 3: Starting Apache and MySQL
Go to the location where you installed XAMPP (usually C:\Program Files\xampp) and double click on XAMPP Control Panel (xampp-control.exe). This will bring you the following screen. Click on Start buttons next to Apache and MySQL for starting them.
Step 4: Now Open Up Your Browser and Type Http://localhost/ or Http://127.0.0.1/
Step 5: This Will Open Up a Following Page. Click on the PhpMyAdmin.
Step 6: This Will Bring You Following Screen. Now Click on the "New" Button As Shown in the Picture Below to Create a New Database.
Step 7: Now Create New Database As Shown in the Picture Below.
Step 8: Now Create a Table to Visualize Data As Shown in the Picture Below.
Step 9: Now Name the First Column As "id".
Step 10: Now Scroll to the Right Side of the Screen You Will See "A_I Comments" I.e. Auto Increments and It Is Used Setting Primary Key Which Uniquely Identifies Each Record Within Table. Click on the Checkbox Below It.
Step 11: This Will Bring You Following Screen. Now Click on the "Go" Button.
Step 12: Now Enter the Values of Other Columns
Name = rms_x, Type = DECIMAL, Length/Values = 10,2(i.e up to 2 decimal points) and similarly for all other values and in the last column, you can show created time and click on the save button as shown in the picture below.
Step 13: Now Click on Your Database Name to Expand It and It Will Show Your Table Name, Then Click on It to View How Data Is Shown, As Shown in the Picture Below.
That's all with the setting up of XAMPP.
Step 14: Setting Up Node-red
Now that you have sensors running, we need a way to do something useful with that data.
- First of all, you'll have to install Node-Red.
- Once that’s done, you’ll need to enter your command line, or Power Shell for Windows users, navigate to the directory Node-RED is installed in.
- Now type “npm i ncd-red-wireless node-red-dashboard“. This will install the nodes required to receive data from your wireless sensors and you can start Node-RED once this is done.
- To start node server write node-red in the command prompt or terminal and press enter.
Step 15: Steps to Create the Flow
At this point you’ll be viewing a large blank flow with a long list of nodes on the left-hand side, this sidebar is called the palette.
Step 16: Go Ahead and Drag a Wireless Gateway Node Over to Your Flow Canvas to Get Started
ncd-red-wireless Provides the nodes that manage the serial connection, parse incoming sensor data, filter it by specific parameters, and allow you to configure the wireless sensors
Step 17: Finding Your Wireless Sensors:
When you’ve delivered the node you’ll be able to view the info tab, which contains records about the node’s capability, this tab is well-populated for maximum node-red packages and consists of treasured statistics, often you will now not want to view any other documentation outdoor of the info tab, so hold it in thoughts even as you're building your flows when you have a question approximately how a node works. The next element we want to do is configure the node, when you first add it you’ll note that there is a small triangle at the top right corner next to a blue dot, the triangle indicates that the node wishes extra configuration, the blue dot indicates that the node has no longer but been deployed as part of the flow.
- Double click on the node to open up the configuration options.
- Click on the pencil icon next to the Serial Device field to configure your USB router, this will open a second configuration panel that only has a few options.
Step 18: Click on the Magnifying Glass Next to the Serial Port Field and Select the Port That Corresponds With Your Router, Then Click the “Add” Button on Top.
Step 19: Serial Device Field Will Now Be Populated Based on That Selection, and You Can Click “Done”, You Now Have Direct Access to Your Wireless Sensors! to View the Data Coming In.
Step 20: Now Go Back to Your Palette and Type “debug” Into the Search Field at the Top, Grab One of These Nodes and Drag It to the Right of Your Wireless Gateway
Step 21: Double Click on It and Change “msg.” to “complete Msg Object” Click Done
Step 22: Now Draw a Line Between the Two Nodes, and Click “Deploy” on the Top Right of the Window..
Step 23: Working With the Data:
Now out of your wireless sensors data is gathered and it is output to the “debug” tab, this "debug tab" is placed within the right sidebar subsequent to the information tab. To see the information is available to hit the reset button. In node-red records is surpassed among nodes in a JSON packet. When the msg object comes into the debug tab you may make bigger it to view the overall list of information that comes with it. This is extraordinarily useful in case you need to quickly see which sensors are checking in. The other issue this node gives is an easy way to interchange your router to the network identity that devices in configuration mode document on, simply hit the button on the left of the node and the tool will switch to the configuration network, hit it once more to return it to listening mode. Once we get the wi-fi tool nodes set up, they may be set to routinely configure a sensor whilst it enters configuration mode, so it’s always available to maintain such gateway nodes present at the flow for speedy configuring a device.
Step 24: Adding the Wireless Sensors:
We need to separate wireless sensor records domestically in order that we are able to display it, we could use a switch node to split out the messages from the gateway based totally on the mac address with or sensor type, but as I referred to, the wireless nodes truly incorporate extra functionality for configuring the sensors, so we’ll start with them to give you an extra entire image of how those structures can work. In case you haven’t already seen packets coming in from both of your sensors, cross in advance and hit the reset button on the only that hasn’t started. While a sensor assessment in through any serial device configuration node, the mac address and kind of sensor is cached in a pool so we are able to quickly find it for the duration of this next step.
- Grab a Wireless Node from the palette and drag it onto the flow, double click on it to get it configured.
Step 25: Select the Serial Device From the Drop Down That You Used for the Wireless Gateway, Now Click the Magnifying Glass Next to “Mac Address” and Select One of the Available Options.
Step 26: Click Done
You’ll notice this automatically sets the sensor type for you, you can also give it a name to make it easier to identify. As noted in the info tab, the Serial Device for Config field is optional, and we won’t worry about it right now. The node you have just added effectively works as a filter on incoming sensor data, only passing through data for the mac address, or sensor type if no mac address is present.
Step 27: Now Go Back to Your Palette and Type “debug” Into the Search Field at the Top, Grab One of These Nodes and Drag It to the Right of Your Wireless Gateway
Step 28: Double Click on It and Click Done
Step 29: Adding the Function Nodes
- Now grab a “function” node from the palette, and place it to the right of the Temp/Hum node.
Step 30: Double Click on the Node to Open Up the Configuration Options.
You can edit values as our own.
rms_x = msg.payload.rms_xrms_y = msg.payload.rms_yrms_z = msg.payload.rms_zmax_x = msg.payload.max_xmax_y = msg.payload.max_ymax_z = msg.payload.max_zmin_x = msg.payload.min_xmin_y = msg.payload.min_ymin_z = msg.payload.min_ztemperature = msg.payload.temperaturemsg.topic = "INSERT INTO vibration_temperature ( `rms_x`, `rms_y`, `rms_z`, `max_x`, `max_y`, `max_z`, `min_x`, `min_y`, `min_z`, `temperature`) VALUES ( "+ rms_x +", "+ rms_y +", "+ rms_z +", "+ max_x +", "+ max_y +", "+ max_z +", "+ min_x +", "+ min_y +", "+ min_z +", "+ temperature +");"return msg;
Step 31: Now You Have Add "mysql" Node to Store Data, Check Your Palette If It Is Present There or You Can Click on the Three Bars Present Right Side of Deploy Button As Shown in the Picture Below
Step 32: Now Click on the "Manage Palette" Button.
Step 33: Now Search for Mysql and Click on the 'install' Button As Shown in the Picture
Once its done, you'll see "mysql" node is present in the palette.