This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MQTT data manipulation
#1
Hi,

I'm building a network interface to get data from my engine (RPM, coolant temperature, oil pressure) to OpenPlotter. (Just for the purpose of displaying it with KIP). I thought the easy way to go would be MQTT ...

So I build an application that posts the data to an local MQTT broker (localhost on the RPI running OpenPlotter) So far so good. Everything works like a charm, I can see my updates in the Diagnostic Signal K input window. 

Problem is however the data transmitted over MQTT are treated as text variables and i can't select the fancy gauge's in KIP to display my engine data. 

I guess my question is; is it at all possible to convert the MQTT data back to numeric data for display in KIP? 

I'm using an RPi-3, the interface connects over WiFi

Kind regards,

Koen
  Reply
#2
in a node red function

msg.payload = Number(msg.payload);
return msg;

parseInt() function parses a string argument and returns an integer of the specified radix

parseFloat() function parses an argument and returns a floating point number.

Code:
[{"id":"8084a1c8.ca583","type":"function","z":"3a024bdf.b11714","name":"","func":"\nmsg.payload = Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":114,"y":352,"wires":[[]]}]
mare liberum
  Reply
#3
What about sending the data as signalk over wifi ? I do very similar with as esp32.



Code:
void sendSigK(String sigKey, float data)
{

 if (sendSig_Flag == 1)
 {
   DynamicJsonBuffer jsonBuffer;
   String deltaText;

   //  build delta message
   JsonObject &delta = jsonBuffer.createObject();

   //updated array
   JsonArray &updatesArr = delta.createNestedArray("updates");
   JsonObject &thisUpdate = updatesArr.createNestedObject();   //Json Object nested inside delta [...
   JsonArray &values = thisUpdate.createNestedArray("values"); // Values array nested in delta[ values....
   JsonObject &thisValue = values.createNestedObject();
   thisValue["path"] = sigKey;
   thisValue["value"] = data;

   thisUpdate["Source"] = "ESP32";

   // Send UDP packet
   Udp.beginPacket(remoteIp, remotePort);
   delta.printTo(Udp);
   Udp.println();
   Udp.endPacket();
 }
}
  Reply
#4
(05-13-2019, 03:52 AM)PaddyB Wrote: What about sending the data as signalk over wifi ? I do very similar with as esp32.



Code:
void sendSigK(String sigKey, float data)
{

 if (sendSig_Flag == 1)
 {
   DynamicJsonBuffer jsonBuffer;
   String deltaText;

   //  build delta message
   JsonObject &delta = jsonBuffer.createObject();

   //updated array
   JsonArray &updatesArr = delta.createNestedArray("updates");
   JsonObject &thisUpdate = updatesArr.createNestedObject();   //Json Object nested inside delta [...
   JsonArray &values = thisUpdate.createNestedArray("values"); // Values array nested in delta[ values....
   JsonObject &thisValue = values.createNestedObject();
   thisValue["path"] = sigKey;
   thisValue["value"] = data;

   thisUpdate["Source"] = "ESP32";

   // Send UDP packet
   Udp.beginPacket(remoteIp, remotePort);
   delta.printTo(Udp);
   Udp.println();
   Udp.endPacket();
 }
}

Mmm, that is worth a try, but wouldn't that be about the same and cause way more network load than MQTT does? MQTT allows for vast updates with very little network load.

Still the problem would be that the SK "propulsion.engine.revolutions" does not show up in KIP configuration screen. I tried entering it manually but the gauge still does not get updated. Also see: this link that is kind of a duplicate ... I did not realize the moderator had to approve posts before they where published and thought my discussion got lost. Maybe the moderator can close one of the posts?
  Reply
#5
(05-13-2019, 07:05 AM)KKempeneers Wrote: Mmm, that is worth a try, but wouldn't that be about the same and cause way more network load than MQTT does? MQTT allows for vast updates with very little network load.

Still the problem would be that the SK "propulsion.engine.revolutions" does not show up in KIP configuration screen. I tried entering it manually but the gauge still does not get updated. Also see: this link that is kind of a duplicate ... I did not realize the moderator had to approve posts before they where published and thought my discussion got lost. Maybe the moderator can close one of the posts?

The traffic sending signalk upd is next to nothing really, doubt if it could be a problem. Bonus is it goes straight into signalk as a number rather than a string so should show up in KIP without a node-red function to convert the string to a number. And easier to send to a database. 
Does your mqtt data show up in kip with a widget set to text value?
  Reply
#6
Well ... I made it so that it is interpreted as an integer by now, the revolutions are now read as an integer by MQTT (Just by selecting the correct Signal K key, see below)

   

Data is read correctly with just a few bytes network load. (see below) I will try the UDP solution and compare. 

   

When it was treated as text i could read the key and the data in KIP, now i can't anymore. 

Koen
  Reply
#7
(05-13-2019, 11:10 AM)KKempeneers Wrote: Well ... I made it so that it is interpreted as an integer by now, the revolutions are now read as an integer by MQTT (Just by selecting the correct Signal K key, see below)



Data is read correctly with just a few bytes network load. (see below) I will try the UDP solution and compare. 



When it was treated as text i could read the key and the data in KIP, now i can't anymore. 

Koen

Bit confused how you've managed to convert from  a string to integer? MQTT is sent as text, just the way it is apparently. Unless the openplotter mqtt tab somehow converts the text value to numerical? I just had a play with node red sending revs as an integer and a string. KIP seems a bit picky when you change path data formats, try setting a widget to blank then back to text and another to blank then  numerical, text values will show up as available path in a text widget. Engine2 below is a text value sent over signalk. 


[Image: 4fJtGCR.png]
  Reply
#8
Hi,

I guess that once the data is received using MQTT and is directed to the correct SignalK key SK just knows to interpret incoming data as a number. It gets a unit and all.

I was just fiddling around with the UDP solution:

Looking trough the signal K doc's the json structure should look something like this:


Code:
MESSAGE = {
   "updates": [
       {
           "source": {
               "label": "ArduinoA0",
               },
           "values": [
               {
                   "path": "propulsion.engine.revolutions",
                   "value": 16.341667
                   },
               ]
           }
       ]
   }
 

Should i send it to port 3000 or to 10110 ?
BTW. I really do not like Node-Red. My CPU load peeks to 80% as soon as i start thinking about using Node-Red.
Koen.
  Reply
#9
I use these >
IPAddress remoteIp(10, 10, 10, 1); //
unsigned short remotePort = 55561; // Signalk listens on this port

Something sounds wrong with your node -red, it uses a bit but not that much..
  Reply
#10
Question 
Quote:Should i send it to port 3000 or to 10110 ?

Port 3000 is http/ws and port 10110 NMEA0183 over tcp, so neither.

You need to configure your SK server to accept Signal K over UDP:
/admin/#/serverConfiguration/providers => Add
- Input Type: Signal K
- Signal K Source: UDP
- Port: <your choice>

and then either send directly to the IP of your server or the broadcast address of your local network.

FWIW I think sending SK directly is better than using MQTT: less processing (no MQTT server just shoveling data along), easier to debug (nc -lu <yourport> to see what you are receiving, no extra components between your sender and SK server).

As for KIP not showing the value: is there anything in your browser's log? Do you see the data in /signalk/v1/api/self/? If all else fails you an contact Kip author via Github.

   
  Reply


Forum Jump:


Users browsing this thread: PaddyB, 1 Guest(s)