3

I need to get the CPU temperature from a raspberry pi to the Watson IoT Platform quickstart service.I am doing this by using an exec node in node red with the command vcgencmd measure_temp. I want to send this temperature value as a number to the Watson IOT node but my exec node returns the CPU temperature as "temp=45.2C"` I want to get the temperature as a floating point number. For this I tried to use a function node to substring the temperature part from the string and use the parseFloat() function in javascript. But the function is notified as invalid. Can someone suggest me on how this should be done. I am a beginner in node-red.

sher17
  • 607
  • 1
  • 12
  • 31

1 Answers1

2

The temperature reading can be read as is, using the Exec node and then it can be further refined to suit your needs. In this case, the following code would do the trick:

msg.payload = {"d":{"temp":msg.payload.replace("temp=","").replace("'C\n","")}};
return msg;

You might want to refer the IoT Recipe "Connecting Raspberry Pi as a Device to Watson IoT using Node-RED" that details out the steps along with the Node-RED flow's, that helps you fetch the Raspberry Pi's CPU Temperature and push / upload it to Watson IoT Platform.

Quick Start is definitely a quick and easiest means of option. This recipe introduces to steps on how you can register the Raspberry Pi as a Registered Device and monitor / administer the same using Watson IoT Platform Dashboard.

ddb
  • 2,423
  • 7
  • 28
  • 38