# Publish from Arduino Sketch to Node-Red - wanting to send Values (not strings) - results in \[250, 0\]

**URL:** <https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196>\
**Category:** General\
**Created:** [16 May 2018 06:05 UTC](https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196 "2018-05-16T06:05:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [16 May 2018 06:05 UTC](https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196/1 "2018-05-16T06:05:25Z")

</div>

I posted this earlier today on the Google Group before seeing that these new forums were up and running

Guys  
,

Still a babe in the woods with all this stuff.

Essentially i am trying to send Temperature Values (and later others) from an Arduino with DS18B20 sensors

In the first instance i receive the values and store them as INT - - i then use the following to convert them to Strings to send to the publish topic on the MQTT broker.

The Publish messages get there (and i am receiving Subscribe messages that i am listening for - so i assume my sketch is OK in that regard

Here is the relevant code

void PublishValues()

{  
String temp\_str;  
char temp[5];

```
 TankTemp2 = TankTemp;
 temp_str = String(TankTemp2); //converting ftemp (the float variable above) to a string 
 temp_str.toCharArray(temp, temp_str.length() + 1); //packaging up the data to publish to mqtt whoa...

Serial.print("Publish message to MQTT on Topic/Temperature: ");//all of these Serial prints are to help with debuging
Serial.println(temp);   
MQTT.publish("topic/TankTemperature", temp); //money shot

```

}

TankTemp is defined as an INT initially - then when i was having no luck with that i created a new float TankTemp2 and tried that

The topic on the MQTT server is gettiing the info and displaying it in the Debug Window - however it is always the same value [250, 0]

I have been searching on Google and found many answers by Nick on this - i have tried taking the +1 off the end - however that truncates what i see locally down to a single digit but still gives me the same values at the receiving end [250,0]

Not sure what i am doing wrong here - must be something very obvious - i thought perhaps the 250,0 was Binary/Hex etc - but the value never changes - even when the temperature readings do change on my Arduino.

I am using Arduino IDE 1.8.2 and the included PubSub library with it.

I have an Arduino Mega with inbuilt ethernet.

regards

Craig

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 May 2018 08:00 UTC](https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196/2 "2018-05-16T08:00:38Z")

</div>

```
  int TankTemp = 22;
  float TankTemp2;
  TankTemp2 = TankTemp;
  String temp_str;
  char temp[5];
  temp_str = String(TankTemp2); //converting ftemp (the float variable above) to a string 
  temp_str.toCharArray(temp, temp_str.length() + 1); //packaging up the data to publish to mqtt whoa...

  Serial.print("Publish message to MQTT on Topic/Temperature: ");//all of these Serial prints are to help with debuging
  Serial.println(temp);   
  client.publish("topic/TankTemperature", temp); //money shot

```

Your code above works on my setup (I just added in dummy value of 22 for TankTemp) - does setting a dummy value work for you?  
Simon

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [16 May 2018 10:29 UTC](https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196/3 "2018-05-16T10:29:14Z")

</div>

Just realised my device was rebooting (it sends the mqtt msg before doing it so I did’nt notice it was going wrong)

I changed to  
`char temp[10]`

and all OK - maybe you were getting a different effect from the same issue - give it a go.  
Simon

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [16 May 2018 16:57 UTC](https://discourse.nodered.org/t/publish-from-arduino-sketch-to-node-red-wanting-to-send-values-not-strings-results-in-250-0/196/4 "2018-05-16T16:57:59Z")

</div>

Note sure what is going on - i did a restart on everything - the Arduino, the Virtual Machine that is running my Node-Red and the PC i do the programming from and it is all working now - not sure what was going on.

Thanks for taking the time to play with it and at least validate this part

Craig
