Cruisers Forum
 


Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 09-11-2020, 06:23   #1
Registered User

Join Date: Nov 2019
Posts: 20
UDP MQTT to Openplotter

Hi all

I'm building my own wind sensor (anemometer) and I want to use an ESP32 to send the signal over WIFI.

First I tried the MQTT but I don't understand the openplotter part of that with username/password etc, so I decided the go the easier way and use UDP.

I used Arduino IDE and send my code to the ESP via serial:

Code:
/*
 *  This sketch sends random data over UDP on a ESP32 device
 *
 */
#include <WiFi.h>
#include <WiFiUdp.h>

// WiFi network name and password:
const char * networkName = ".............";
const char * networkPswd = "..............";

//IP address to send UDP data to:
// either use the ip address of the server or 
// a network broadcast address
const char * udpAddress = "10.10.10.133";
const int udpPort = 3333;

//Are we currently connected?
boolean connected = false;

//The udp library class
WiFiUDP udp;

void setup(){
  // Initilize hardware serial:
  Serial.begin(115200);
  
  //Connect to the WiFi network
  connectToWiFi(networkName, networkPswd);
}

void loop(){
  //only send data when connected
  if(connected){
    //Send a packet
    udp.beginPacket(udpAddress,udpPort);
    udp.printf("Seconds since boot: %lu", millis()/1000);
    udp.endPacket();
  }
  //Wait for 1 second
  delay(1000);
}

void connectToWiFi(const char * ssid, const char * pwd){
  Serial.println("Connecting to WiFi network: " + String(ssid));

  // delete old config
  WiFi.disconnect(true);
  //register event handler
  WiFi.onEvent(WiFiEvent);
  
  //Initiate connection
  WiFi.begin(ssid, pwd);

  Serial.println("Waiting for WIFI connection...");
}

//wifi event handler
void WiFiEvent(WiFiEvent_t event){
    switch(event) {
      case SYSTEM_EVENT_STA_GOT_IP:
          //When connected set 
          Serial.print("WiFi connected! IP address: ");
          Serial.println(WiFi.localIP());  
          //initializes the UDP state
          //This initializes the transfer buffer
          udp.begin(WiFi.localIP(),udpPort);
          connected = true;
          break;
      case SYSTEM_EVENT_STA_DISCONNECTED:
          Serial.println("WiFi lost connection");
          connected = false;
          break;
      default: break;
    }
}
where I have inserted my wifi and password instead of "........" and through serial monitor I can see that it has successfully connected to the Raspberry network.

In Openplotter under KPLEX I added UDP 10.10.10.133 port 3333 but it does not seem to work. Any ideas ?

Kind Regards,
Peter
peter- is offline   Reply With Quote
Old 15-11-2020, 05:01   #2
Registered User

Join Date: Oct 2012
Location: Brighton, UK
Boat: Westerly Oceanlord
Posts: 513
Re: UDP MQTT to Openplotter

Quote:
Originally Posted by peter- View Post
In Openplotter under KPLEX I added UDP 10.10.10.133 port 3333 but it does not seem to work. Any ideas ?
I'm not especially familiar with openplotter and am certainly no arduino expert but kplex doesn't pass arbitrary data so your "Seconds since boot" string would be dropped as not being an NMEA string.
That string:
- Doesn't start with a $ or ! character
- Doesn't end with nmea-0183 terminating \r\n sequence
- Doesn't have a checksum

kplex doesn't worry about checksums unless you tell it (with "checksum=yes" in the configuration). You can also tell it to be less strict about line termination but it's probably easier to correctly terminate your lines in a printf with \r\n.
Downstream applications may be fussier about checksums so that's obviously something you'll want to add for your final code.

Again, apologies for not being familiar with the openplotter interface but I assume that 10.10.10.133 is an interface on your pi rather than the esp32 in which case you want to ensure that that is configured as an *input* interface for kplex. Not specifying the address explicitly may be easier (ie if you only specify the port for an input interface, kplex will listen on that port on all network interfaces)
muttnik is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
openplotter / MQTT need help ... juancho38 OpenCPN 1 26-08-2019 03:03
Problems with a UDP connection wbickle OpenCPN 6 12-04-2018 08:44
Wiresharking Radar Gofree Navionics Android UDP Mulitcast Sleuthing rgleason OpenCPN 0 20-01-2016 07:19
UDP reuse? rsl360 OpenCPN 12 03-07-2014 22:23
Need help broadcasting NMEA data over a local network using UDP RhythmDoctor OpenCPN 3 02-05-2014 05:53

Advertise Here


All times are GMT -7. The time now is 09:57.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2025, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.