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
SignalK updates over WiFi from ESP32
#1
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.
Reply
#2
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
Reply
#3
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.
Reply
#4
(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
Reply
#5
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.
Reply
#6
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}
Reply
#7
(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"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)