GHA
Well-known member
Fiver for the wifi board, couple quid for the serial converter, maybe a couple for a power supply and then a quid for a box?
This works, sort of so far anyway. I've got it talking to a Raspberry Pi which repeats the data to a laptop, nasa NMEA0183 compass will spin the boat on Opencpn round and round
Should be able to multiplex as well so you can take a AIS feed & GPS feed then send it to a tablet running Opencpn. The AIS display on that program is just great .
Struggling a bit with UDP over internet though, can't get the laptop to see the data over the mobile phone wifi network - and hints anyone? Openplotter (Kplex) in a Pi reads it fine. The ESP can make its own hotspot as well so no need for anything else.
Code below, I'm not a coder so feel free to suggest any enhancements or feel free to copy - shouldn't be too hard to write a web page to set it up.This sends the data out over MQTT as well so if you've a cheap phone on the boat it should be quite easy to set it all up to monitor batteries, temperature, bilges etc..
Enjoy
https://www.ebay.co.uk/itm/NEW-Node...990999?hash=item238e580ed7:g:pgIAAOSwnTxZbPEf
http://www.ebay.co.uk/itm/Mini-RS23...032828&hash=item1a21362809:g:ll4AAOSwA3dYRL3d
This works, sort of so far anyway. I've got it talking to a Raspberry Pi which repeats the data to a laptop, nasa NMEA0183 compass will spin the boat on Opencpn round and round
Should be able to multiplex as well so you can take a AIS feed & GPS feed then send it to a tablet running Opencpn. The AIS display on that program is just great .
Struggling a bit with UDP over internet though, can't get the laptop to see the data over the mobile phone wifi network - and hints anyone? Openplotter (Kplex) in a Pi reads it fine. The ESP can make its own hotspot as well so no need for anything else.
Code below, I'm not a coder so feel free to suggest any enhancements or feel free to copy - shouldn't be too hard to write a web page to set it up.This sends the data out over MQTT as well so if you've a cheap phone on the boat it should be quite easy to set it all up to monitor batteries, temperature, bilges etc..
Enjoy
Code:
/** This sketch sends broadcast udp message.
*
*
*/
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <PubSubClient.h> // mqtt library
#define mqtt_server "10.10.10.1"
#define mqtt_user "User"
#define mqtt_password "Password"
const char* ssid = "OpenPlotter";
const char* password = "password";
//const char* ssid = "*****";
//const char* password = "*******";
IPAddress ipBroadCast(10, 10, 10, 255);
unsigned int udpRemotePort=10112;
unsigned int udplocalPort=2390;
const int UDP_PACKET_SIZE = 70;
char udpBuffer[ UDP_PACKET_SIZE];
String inData;
WiFiUDP udp;
WiFiClient espClient;
PubSubClient client(espClient);
SoftwareSerial mySerial(14, 12);
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
char receivedChar = (char)payload[i];
Serial.print(receivedChar);
}
Serial.println();
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
// If you do not want to use a username and password, change next line to
// if (client.connect("ESP8266Client")) {
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
Serial.println("connected");
client.subscribe("myfirstin");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
//================================================================
// Setup hardware, serial port, and connect to wifi.
//================================================================
void setup() {
Serial.begin(115200);
mySerial.begin(4800);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
// Try to connect to wifi access point
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
// set udp port for listen
udp.begin(udplocalPort);
Serial.print("Local port: ");
Serial.println(udp.localPort());
client.setServer(mqtt_server, 1883); //start mqtt
client.setCallback(callback); // set callback routine to monitor incoming mqtt
client.subscribe("myfirst");
}
//================================================================
// Function to send udp message
//================================================================
void fncUdpSend(String inData)
{
char temp[50];
inData.toCharArray(temp, 50) ;
udp.beginPacket(ipBroadCast, udpRemotePort);
udp.write(temp, sizeof(temp));
udp.endPacket();
Serial.print("sent - ");
Serial.println(inData);
}
//================================================================
// LOOP MAIN
//================================================================
void loop() {
while (mySerial.available() > 0) {
char recieved = mySerial.read();
inData+= recieved;
// Process message when new line character is recieved
if (recieved == '\n')
{
Serial.print("Arduino Received: ");
Serial.print(inData);
fncUdpSend(inData);
char temp[50];
inData.toCharArray(temp, 50) ;
client.publish("myfirstout", temp);
inData = ""; // Clear recieved buffer
}
}
// if (!client.connected()) {
// reconnect();
//}
//client.loop();
}
https://www.ebay.co.uk/itm/NEW-Node...990999?hash=item238e580ed7:g:pgIAAOSwnTxZbPEf
http://www.ebay.co.uk/itm/Mini-RS23...032828&hash=item1a21362809:g:ll4AAOSwA3dYRL3d