I am trying to send data (DHT22) from an MKR1310 to emoncms via MQTT (Node-Red). The MQTT data seems to be going out but because of errors it’s not being accepted by emoncms.
The emoncms.log shows:
I think it’s a json format problem but am no expert here and need some help. I will attach a file of various data and will send anything else needed. I have several LoRaWAN data streams going into the emoncms server which all work as intended.
Thanks in advance
Cheers,
Bob
MKR1310_emoncms.txt (1.6 KB)
Sorry, the missing error that didn’t show up is:
2024-11-02 14:33:56.469|ERROR|input_controller.php|{"success": false, "message": "Request contains no data via csv, json or data tag"} for User: 1
borpin
(Brian Orpin)
4 November 2024 09:59
3
In Node-RED, create a debug node so you can see what is being sent to the MQTT publish node.
What does the Payload look like?
Thanks, Brian, the debug info is in the file I attached to my initial message. Here it is in case it didn’t come through correctly. Sorry, I can’t seem to format correctly from my ipad.
==================================
Node-Red data plus error:
11/2/2024, 10:47:11 AMnode: 7662c054953ac5a4application/49/device/3930313052317908/rx : msg.payload : Object
object
applicationID: "49"
applicationName: "mkr1310"
deviceName: "mkr1310"
deviceProfileName: "mkr1310-device"
deviceProfileID: "4f2437ec-ed99-43e5-8931-614b53d6eb56"
devEUI: "3930313052317908"
txInfo: object
adr: true
fCnt: 2285
fPort: 1
data: "CRoQ6g=="
object: object
humidity: 4098
temperature: 2304
11/2/2024, 10:47:11 AMnode: Emoncms Push
msg : Object
object
topic: "http response"
payload: object
qos: 0
retain: false
_msgid: "7db47a2367fbab25"
urlsent: "http://192.168.1.174/input/post.json?json={"applicationID":"49","applicationName":"mkr1310","deviceName":"mkr1310","deviceProfileName":"mkr1310-device","deviceProfileID":"4f2437ec-ed99-43e5-8931-614b53d6eb56","devEUI":"3930313052317908","txInfo":{"frequency":904500000,"dr":0},"adr":true,"fCnt":2285,"fPort":1,"data":"CRoQ6g==","object":{"humidity":4098,"temperature":2304}}&node=mkr1310&apikey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
rc: 200
warning: "ERROR: API Call Failed"
borpin
(Brian Orpin)
10 November 2024 16:29
5
It needs to be a simple JSON with {key:value } pairs and no non-numeric values.
You might also find it easier just to send via MQTT.
Alternatively, select
I have selected the data type JSON as you suggest. My function node is probably incorrect:
input = msg.payload
var temperature = input.object.temperature
var humidity = input.object.humidity
msg2 = {payload:{"temperature":temperature, "humidity":humidity}};
return msg2;
I’m not a programmer so am lost here. Can you suggest the correct data for my function?
I’m sending this data from the LoRa gateway to emoncms.
Cheers,
Bob
borpin
(Brian Orpin)
11 November 2024 09:00
7
If you are not comfortable programming, a change node might be better to extract the right bit of data (Google or CoPilot is your friend)
If I assume the incoming structure is such that your variables are created correctly,
var newmsg = {};
newmsg.payload = {};
newmsg.payload.temperature = msg.payload.object.temperature;
newmsg.payload.humidity = msg.payload.object.humidity;
return newmsg;
I’ve cobbled that from something else I do. Long time since I have needed to play with functions (everything is setup and works )
Add ‘DEBUG’ nodes along the way so you see what your data looks like at each stage.
It appears in the right hand pane if you select ‘debug’
1 Like
Many thanks, Brian (@borpin ) that worked and was what I needed. Much appreciated!
Cheers,
Bob
11/11/2024, 10:01:47 AMnode: d4b7831378633552
msg.payload : Object
object
temperature: 2050
humidity: 4609
1 Like