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
UDP Issues - UDP message to SignalK from ESP8266
#3
I've got it working here just with  dummy message, actually 2 of esp8266 sending SOG & COG messages. 

Code is just a messy try out but works this end. The code can be uploaded over the air as well, no need to plug into the 8266 - upload over wifi, really handy. 
http://esp8266.github.io/Arduino/version...dates.html

Another way to go is to use easyesp and send the data as MQTT which openplotter can then map to a signalk update. 

Code:
#include <ESP8266WiFi.h>

#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "openplotter";
const char* password = "12345678";

unsigned int localPort = 55557;      //  port to  send  UDP packets



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

void setup() {
 Serial.begin(115200);
 Serial.println("Booting");
 WiFi.mode(WIFI_STA);
 WiFi.begin(ssid, password);
 while (WiFi.waitForConnectResult() != WL_CONNECTED) {
   Serial.println("Connection Failed! Rebooting...");
   delay(5000);
   ESP.restart();
 }

 // Port defaults to 8266
 // ArduinoOTA.setPort(8266);

 // Hostname defaults to esp8266-[ChipID]
 // ArduinoOTA.setHostname("myesp8266");

 // No authentication by default
 // ArduinoOTA.setPassword("admin");

 // Password can be set with it's md5 value as well
 // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
 // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

 ArduinoOTA.onStart([]() {
   String type;
   if (ArduinoOTA.getCommand() == U_FLASH)
     type = "sketch";
   else // U_SPIFFS
     type = "filesystem";

   // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
   Serial.println("Start updating " + type);
 });
 ArduinoOTA.onEnd([]() {
   Serial.println("\nEnd");
 });
 ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
   Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
 });
 ArduinoOTA.onError([](ota_error_t error) {
   Serial.printf("Error[%u]: ", error);
   if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
   else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
   else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
   else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
   else if (error == OTA_END_ERROR) Serial.println("End Failed");
 });
 ArduinoOTA.begin();
 Serial.println("Ready");
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());
 Udp.begin(localPort);
 pinMode(2, OUTPUT);
}

void loop() {
 ArduinoOTA.handle();
 
 digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(500); // wait for 1/2 second
 digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
 delay(1000);

 
 int value = random(20);  // create a random vaue between 0 and 20 to simulate SOG
 String tempString = "{\"updates\": [{\"$source\": \"OPsimulation\",\"values\":[ {\"path\":\"navigation.courseOverGroundTrue\",\"value\":\"";   //  create 1st part of signalk string
     
 tempString += String(value);  //add simulated SOG to string
 tempString += "\"}]}]}\n" ;   // finish the signelK string

 char  replyPacekt[tempString.length()+1] ;  //initialise char array for UDP

 tempString.toCharArray(replyPacekt, tempString.length()+1);   // add the signalk string to char array


// send the char array as UDP
 IPAddress  ip = IPAddress(10,10,10,1);
 Udp.beginPacket(ip, localPort);    //signalk server on Pi listens on 10.10.10.1 port 55557
 Udp.write(replyPacekt);
 Udp.endPacket();

}
Reply


Messages In This Thread
RE: UDP Issues - UDP message to SignalK from ESP8266 - by PaddyB - 2018-03-16, 03:19 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)