I am trying to use the Twitter node for the first time.
As an initial trial I am feeding the output from an 18B20 temperature sensor (using "rpi-ds18b20") node to the "Twitter out" node. All on a Raspberry Pi 3B+ running Buster.
The temperature gives me a floating point number and the Twitter node expects a string. I can see the value in a debug node and I also publish it to MQTT - so that part is working.
I have been through setting up the Twitter developer account and gave it the various strings and secrets.
So I get the error in the title "TypeError: msg.payload.slice is not a function", I assume because the 18B20 is pulishing a floating point number and the Twitter node expects a string.
I tried to convert the number to a string using ....
return msg;```
But that didn't work!
My Javascript is pretty (very) poor - can someone suggest how to fix it?
Thanks
Bruce
Add a debug node showing what is going to the twitter node. Set the debug node to Show Complete Message.
Also tell us which twitter node you are using, there are several. Is it node-red-node-twitter?
.. i havent used twitter node .. but according to your previous posts .. if tweeter node expects a string in payload .. then you should have a function node between Study temp and Tweet node
that has your float to string convertion :
That is coming from the Twitter API. You cannot tweet the same text twice in a row.
There was a recent thread on this same issue - the Twitter node doesn't handle number types... It assumes you are giving it a string message as tweeting bare numbers isn't really what twitter is for (and could fall foul of their terms of service)
OK so I added a time field to make the Tweets unique as suggested by E1cid. By the way Twitter won't let you repeat a Tweet for 24 hours.
Code is
'''let newMsg = {}; // start new
let today = new Date();
newMsg.payload = (msg.payload).toString() + " C is the study temperature at "+today.getHours()+":"+today.getMinutes();
return newMsg;'''
That works but I need to fix having a leading zero in the minutes field.