OpenMarine

Full Version: UDP MQTT to Openplotter with ESP32
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2020-11-10, 11:50 AM)Peter— Wrote: [ -> ]But I guess it’s a format where I have to state e.g that it’s a temp value and it’s measure in degC, or a wind value in this case, measured in knts.

Signalk works in SI units, so temperature is Deg Kelvin, speed is in M/S, direction is in radians etc. 

No need for node red, send a JSON formatted string to signalk and that's it .

Like this >

{
    "updates": [
        {
            "source": {
                "type": "NMEA0183",
                "sentence": "GLL",
                "label": "OPkplex",
                "talker": "GP"
            },
            "timestamp": "2017-07-26T12:21:15.000Z",
            "values": [
                {
                    "path": "navigation.position",
                    "value": {
                        "longitude": -7.846666666666667,
                        "latitude": 36.9987
                    }
                }
            ]
        }
    ]
}
(2020-11-10, 01:34 PM)PaddyB Wrote: [ -> ]
(2020-11-10, 11:50 AM)Peter— Wrote: [ -> ]But I guess it’s a format where I have to state e.g that it’s a temp value and it’s measure in degC, or a wind value in this case, measured in knts.

Signalk works in SI units, so temperature is Deg Kelvin, speed is in M/S, direction is in radians etc. 

No need for node red, send a JSON formatted string to signalk and that's it .

Like this >

{
    "updates": [
        {
            "source": {
                "type": "NMEA0183",
                "sentence": "GLL",
                "label": "OPkplex",
                "talker": "GP"
            },
            "timestamp": "2017-07-26T12:21:15.000Z",
            "values": [
                {
                    "path": "navigation.position",
                    "value": {
                        "longitude": -7.846666666666667,
                        "latitude": 36.9987
                    }
                }
            ]
        }
    ]
}

So would this work?

{
 “Vessel”: {
     “Outside”: {
          “Temperature”: 300
                       }
                }
}
(2020-11-10, 02:13 PM)Peter— Wrote: [ -> ]So would this work?

{
 “Vessel”: {
     “Outside”: {
          “Temperature”: 300
                       }
                }
}

Afraid not, try it for yourself , in the data fiddler >
[Image: a0evGiZ.png]
(2020-11-10, 06:10 PM)PaddyB Wrote: [ -> ]
(2020-11-10, 02:13 PM)Peter— Wrote: [ -> ]So would this work?

{
 “Vessel”: {
     “Outside”: {
          “Temperature”: 300
                       }
                }
}

Afraid not, try it for yourself , in the data fiddler >
[Image: a0evGiZ.png]

That is a great tool, thanks PaddyB.

I'm on a slack channel learning about it, and I'll update you guys when I know more. Currently this is what I expect to be the format:

Code:
{
    "updates": [    
        {
        "source": {
            "values":[
                {
                "path": "environment.outside.temperature",
                "value": 300
                }
                ]
            }
        }
        ]
}

Kind Regards,
Peter
Ok I'm stuck.

Here is my code:

Code:
#include "WiFi.h"
#include "AsyncUDP.h"

const char * ssid = "hidden";
const char * password = "hidden";

AsyncUDP udp;

void setup()
{
   Serial.begin(115200);
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid, password);
   if (WiFi.waitForConnectResult() != WL_CONNECTED) {
       Serial.println("WiFi Failed");
       while(1) {
           delay(1000);
       }
   }
   if(udp.connect(IPAddress(10,10,10,1), 3333)) {
       Serial.println("UDP connected");
       udp.onPacket([](AsyncUDPPacket packet) {
           Serial.print("UDP Packet Type: ");
           Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
           Serial.print(", From: ");
           Serial.print(packet.remoteIP());
           Serial.print(":");
           Serial.print(packet.remotePort());
           Serial.print(", To: ");
           Serial.print(packet.localIP());
           Serial.print(":");
           Serial.print(packet.localPort());
           Serial.print(", Length: ");
           Serial.print(packet.length());
           Serial.print(", Data: ");
           Serial.write(packet.data(), packet.length());
           Serial.println();
           //reply to the client
           packet.printf("Got %u bytes of data", packet.length());
       });
       //Send unicast
       udp.print("Hello Server!");
   }
}

void loop()
{
   delay(1000);
   //Send broadcast on port 3333
//    udp.broadcastTo("this is now working", 3333);
   Serial.println("Sending packages....    ");
   Serial.println(millis()/1000);
//    udp.print("$INMTW,17.9,C*1B");

 udp.print("{\"updates\":[{\"source\":{");
 udp.print("\"values\":[{\"path\":\"environment.outside.temperature\",\"value\":");
 udp.print(millis()/1000);
 udp.print("}]}}]}");
}

On my PI, I can use netcat on the 3333 port and see the JSON-DELTA UDP sentence, so I know it transmitting and recieving. If I copy the netcat output into the SignalK datafiddler it is valid, so I know the format is correct. I have added the connection in SignalK as a Signalk connection on port 3333 with "no self mapping" and logging disabled. When I look in the SignalK diagnose tool there is no temperature readings. What am I missing?

Kind Regards,
Peter
Ok so it seems I got it working by putting by it all into one udp.print command - at least the WiFi icon on my data connection in SignalK is showing that it is receiving information by flashing. However, the data is not showing in my diagnose tool nor on my instrument panels.

I have checked the format in the fiddler and it seems correct. Any ideas how to get it up on the instruments?

Update: The serve log states: "Cannot read property 'length' of undefined "
Hi all

I got it working. I'll make a guide within the next week explaining this in more detail. Here is my final code:

Code:
#include "WiFi.h"
#include "AsyncUDP.h"

const char * ssid = "INSERT YOUR SSID HERE";
const char * password = "INSERT YOUR WIFI PASSWORD HERE";

AsyncUDP udp;

void setup()
{
   Serial.begin(115200);
   WiFi.mode(WIFI_STA);
   WiFi.begin(ssid, password);
   if (WiFi.waitForConnectResult() != WL_CONNECTED) {
       Serial.println("WiFi Failed");
       while(1) {
           delay(1000);
       }
   }
   if(udp.connect(IPAddress(10,10,10,1), 3333)) {
       Serial.println("UDP connected");
       udp.onPacket([](AsyncUDPPacket packet) {
           Serial.print("UDP Packet Type: ");
           Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
           Serial.print(", From: ");
           Serial.print(packet.remoteIP());
           Serial.print(":");
           Serial.print(packet.remotePort());
           Serial.print(", To: ");
           Serial.print(packet.localIP());
           Serial.print(":");
           Serial.print(packet.localPort());
           Serial.print(", Length: ");
           Serial.print(packet.length());
           Serial.print(", Data: ");
           Serial.write(packet.data(), packet.length());
           Serial.println();
           //reply to the client
           packet.printf("Got %u bytes of data", packet.length());
       });
       //Send unicast
       udp.print("Hello Server!");
   }
}

void loop()
{
 delay(1000);
 long temp = (millis()/1000);
 char udpmessage[1024];
 sprintf(udpmessage, "{\"updates\":[{\"$source\":\"esp32.outside.temp\",\"values\":[{\"path\":\"environment.outside.temperature\",\"value\":%d}]}]}", temp);
 udp.print(udpmessage);
 Serial.println(udpmessage);
}

Many thanks for the help guys
Peter
Great, well done!
(2020-11-11, 08:32 PM)PaddyB Wrote: [ -> ]Great, well done!

Thanks PaddyB

I did the same for apparent wind speed (which is actually what I want) and it worked perfectly as well. However, I wasn’t able to get it into the dashboard in OpenCPN. Any ideas how to do that?

Br, Peter
Looks like it must be nmea code for OpenCPN, but someone wrote that OpenCPN should soon be able to receive SignalK so I’m not going to waste my time on this before I have my system ready and hopefully by spring OpenCPN will include it.

Br, Peter
Pages: 1 2 3