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.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Humidity Sensor -> MQTT -> SignalK (data conversion)
#1
I have a sensor collecting humidity data and using the following to send to MQTT.

      pubString = String(dht.getHumidity()/100); 
      memset(msg, 0, sizeof(msg));
      pubString.toCharArray(msg, pubString.length()+1); 
      client.publish("SensorHumidity",msg);

I am trying to display the humidity data in Wilhelm but it is being recognized, correctly as a string in Wilhelm rather than a float. How do I send the data so it ends up as being float in SignalK and hence Wilhelm as well? I have data getting on to Wilhelm, I suspect I am just not doing it the right way. I am NOT familiar with a whole JSON structure but do I need to go to that extent to accomplish what I am trying?  A shove in right direction would be appreciated. Signed Newbie, but learning
Reply
#2
(2018-09-29, 03:15 PM)awwbaker@yahoo.com Wrote: I have a sensor collecting humidity data and using the following to send to MQTT.

      pubString = String(dht.getHumidity()/100); 
      memset(msg, 0, sizeof(msg));
      pubString.toCharArray(msg, pubString.length()+1); 
      client.publish("SensorHumidity",msg);

I am trying to display the humidity data in Wilhelm but it is being recognized, correctly as a string in Wilhelm rather than a float. How do I send the data so it ends up as being float in SignalK and hence Wilhelm as well? I have data getting on to Wilhelm, I suspect I am just not doing it the right way. I am NOT familiar with a whole JSON structure but do I need to go to that extent to accomplish what I am trying?  A shove in right direction would be appreciated. Signed Newbie, but learning

What are you using to send the data? If it's an esp then this library might help , I stole some of it and send signalk direct so no problems with the data. Had the same issues with mqtt sending the data as a string.

https://github.com/mxtommy/EspSigK
Reply
#3
(2018-09-29, 05:22 PM)PaddyB Wrote:
(2018-09-29, 03:15 PM)awwbaker@yahoo.com Wrote: I have a sensor collecting humidity data and using the following to send to MQTT.

      pubString = String(dht.getHumidity()/100); 
      memset(msg, 0, sizeof(msg));
      pubString.toCharArray(msg, pubString.length()+1); 
      client.publish("SensorHumidity",msg);

I am trying to display the humidity data in Wilhelm but it is being recognized, correctly as a string in Wilhelm rather than a float. How do I send the data so it ends up as being float in SignalK and hence Wilhelm as well? I have data getting on to Wilhelm, I suspect I am just not doing it the right way. I am NOT familiar with a whole JSON structure but do I need to go to that extent to accomplish what I am trying?  A shove in right direction would be appreciated. Signed Newbie, but learning

What are you using to send the data? If it's an esp then this library might help , I stole some of it and send signalk direct so no problems with the data. Had the same issues with mqtt sending the data as a string.

https://github.com/mxtommy/EspSigK

------------------------------------------------------------------------------
First of all....complete NUBE!!! That said, I have put together an Mega 2560 Arduino based board which is measuring solar panel current, voltage as well as a temperature and humidity sensor. I am using

WiFiEspClient espClient;
PubSubClient client(espClient);

to send the data to MQTT broker on OpenPlotter running on a RPi. Using the interface there I mapped MQTT messages to SignalK. I then started up Wilhelm used generic controls to display....all working and very cool. Then tried to use Temperature and Ratio Controls. The Wilhelm author Mr Bender discovered I was sending strings rather than numerical values through MQTT. 

I tried building the EspSigK example but I suspect because of the Mega 2560 getting build errors that are currently beyond my skill level to resolve. (error on some includes in EspSigK.h) At this point not sure if I should abandon the MQTT and go after the EspSigK? Any suggestions GREATLY appreciated. VR Anthony
Reply
#4
(2018-09-29, 08:42 PM)awwbaker@yahoo.com Wrote: ------------------------------------------------------------------------------
First of all....complete NUBE!!! That said, I have put together an Mega 2560 Arduino based board which is measuring solar panel current, voltage as well as a temperature and humidity sensor. I am using

WiFiEspClient espClient;
PubSubClient client(espClient);

to send the data to MQTT broker on OpenPlotter running on a RPi. Using the interface there I mapped MQTT messages to SignalK. I then started up Wilhelm used generic controls to display....all working and very cool. Then tried to use Temperature and Ratio Controls. The Wilhelm author Mr Bender discovered I was sending strings rather than numerical values through MQTT. 

I tried building the EspSigK example but I suspect because of the Mega 2560 getting build errors that are currently beyond my skill level to resolve. (error on some includes in EspSigK.h) At this point not sure if I should abandon the MQTT and go after the EspSigK? Any suggestions GREATLY appreciated. VR Anthony

So is it sending over Wifi or serial? Either way there'll be a way to send as signalk intead of mqtt - you could maybe try this function I pinched and tweaked, think it was from espsigk.  Not sure if that will work but worth a try, #include.... goes at the top then the WifiUDP above the setup. 
So to send just go >

"sendSigK("mytest.test", 12345 );"

You might need to add the json library, in the arduino IDE go into Sketch|include Library|manage libraries and search fo arduinojson, might be better not to add a beta librry, but go for an earlier one. 

Good luck, for a nube you seem to have hit the ground running!!! :Cool



Code:
#include <ArduinoJson.h>
#include <WiFiUdp.h>


WiFiUDP Udp;        // A UDP instance to let us send and receive packets over UDP



void sendSigK(String sigKey, float data) {    //    send SigK via UDP *****************************************


 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"] = "ESP11";

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

 Serial.print("UDP sent. remoteIP = ");
 Serial.println(remoteIp);
 Serial.print("remote port = ");
 Serial.println(remotePort);
 Serial.print("Wifi mode = ");
 Serial.println(WiFi.getMode());


}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)