Hi,
I'm building an IoT MQTT platform with node red and a mysql database.
My MQTT connection is working fine as well as the database connections.
However I need to store a connected device ID in my device tabel.
Every time I receive data the device ID is send along with it so I extract the device ID from my msg.payload.
Now I first want to check if the device ID already exists in my tabel with a query.
Currently I'm doing this whith the following query:
var strQuery = "SELECT COUNT(sensorADDR) FROM co2sensor WHERE sensorADDR = "+serverADDR+";";
When the device ID doesn't exist in the tabel I would like to add it to my device tabel using.
var strQuery2 = "INSERT INTO co2sensor (sensorADDR) VALUES ('"+serverADDR+"');";
So in essence I want to do the following.
if( COUNT(deviceID) == 0)
{
var strQuery2 = "INSERT INTO co2sensor (sensorADDR) VALUES ('"+serverADDR+"');";
}
else
{
Other code
}
I've tried the following
But I lose my original data from the test mqtt out.
Can anyone help me with this problem?
With kind regards
Sébastien