OpenMarine

Full Version: SignalK updates over WiFi from ESP32
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm trying, without any luck i might add to post sensordata to SignalK 2.7.2. using a ESP32 module over Wifi. I've been doing that using Python and C++. The only thing that seems to be happening;
  • I can send a curl request from the RPi terminal window requesting acces,
  • I can approve the access (i.e. I get a device ID),

But than i puzzled, what is the next step? 

Sorry to say this but i'm kind a wondering is all that security not a bit over the top? When someone tries to hack in to my closed network on the boot i have bigger problems than my instruments being unusable.

Anyway, can someone pleas provide me with a good example in either C++ or Python that sends a SignalK update. And also, is it really necessary to add a timestamp on every update? If so can it be requested from the server? I do not want to add a RTC on something as stupid as a compass sensor.

Kind regards,

Koen.
I use micropython, create a data connection type signalk port 10119 then this code works for me, this is inside a class otherwise probably no need for the "self, ... >

import socket
def insertIntoSigKdata(self, path, value):
# https://wiki.python.org/moin/UdpCommunication
try:
UDP_IP = "10.42.0.1"
UDP_PORT = 10119
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_sigKdata = {"updates": [{"values":[]}]}
_sigKdata["updates"][0]["values"].append( {"path":path,"value": value})
MESSAGE = (ujson.dumps(_sigKdata))
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.close()
except Exception as e:
print("Send signalk error = ",e)


the server will add a timestamp
Well sorry to say that did not help ... i'm able to send the message but no one is listening, it certainly does not show up in the databrowser.

I have a connection set up but nothing shows up. 

Koen.
(2024-05-07, 04:48 PM)KKempeneers Wrote: [ -> ]Well sorry to say that did not help ... i'm able to send the message but no one is listening, it certainly does not show up in the databrowser.

I have a connection set up but nothing shows up. 

Koen.

Is the esp32 connecting to the openplotter wifi network OK? 

Actually that IP address could be wrong, that's from opV4 on bookworm, if you are on opV3 it's more likely 10.10.10.1.

This is very messy & very old & I'm not even a programmer Smile but most of it should work, any useful bits feel free to copy >>

https://github.com/boatybits/boatymonpy/tree/beta
The problem is either with the UDP communications or with the payload not being correct.

You can verify that UDP is working by activating debug key signalkConfusedtreams:udp in Server Log. If there is no output in Server Log comms is not working.

If UDP works but there is nothing in Data Browser the problem is in the payload.
Sorry i could not answer sooner ... upon tkurki's suggestion i dove in the server logs and found that the Signal K message was improper formated.  

For future reference, the C++ (Arduino code) should be:

String makeSignalKDelta(const char* topic, float data) {
  String SignalKDelta;
  DynamicJsonDocument doc(256);


  // Create the Signal K Delta message
  JsonArray updatesArray = doc.createNestedArray("updates");
  // Create an object within the updates array
  JsonObject updateObject = updatesArray.createNestedObject();
  // Create the values array within the update object
  JsonArray valuesArray = updateObject.createNestedArray("values");
  // Create an object within the values array
  JsonObject value = valuesArray.createNestedObject();
 
  value["path"] = topic;
  value["value"] = data;  
 
  serializeJson(doc, SignalKDelta);
  return SignalKDelta;
}

(You must include ArduinoJson.h in order to compile) With that sorted out ... how can i read data from the SignalK server? And are there aftermarket displays that withstand the weather and understand SignalK? Which one would you suggest? I realy would like the dept sounder and wind instrument on a display in the cockpit. 
 to server: 10.10.10.1

95 bytes written.

{"updates":[{"values":[{"path":"vessels.self.propulsion.0.revolutions","value":38.483}
(2024-05-11, 07:43 PM)KKempeneers Wrote: [ -> ]... how can i read data from the SignalK server? 

95 bytes written.

{"updates":[{"values":[{"path":"vessels.self.propulsion.0.revolutions","value":38.483}

One way is 
HTTP  get "http://10.10.0.1:3000/signalk/v1/api/vessels/urn:mrn:imo:mmsi:"YOUR_MMSI"/environment/wind/speedTrue/value"