Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

3,722

5

44

Introduction: Cheap NMEA/AIS Hub -- RS232 to Wifi Bridge for Onboard Use

Update 11th Jan 2022 – Added DHCP and note about static IP's in Step 6 Help - No Data
Update 9th August 2021 – Fixed links to pfodESP8266BufferedClient library
Update 9th January 2021 – Added extra TCP connection and reuse last connection if more clients connect
Update 13th December 2020 – Added no config version of the code.

Introduction

This NMEA / AIS RS232 to WiFi bridge is based on the ESP8266-01 WiFi Shield. AIS is automatic identification system to show the position of nearby ships. NMEA 0183 is the National Marine Electronics Association standard used for GPS messages.

The RS232 to WiFi bridge has been modified from the ESP8266-01 WiFi Shield to be powered by a 12V battery and accept an RS232 input (+/-15V) and create a local network which broadcasts the data via TCP and UDP. It was developed in conjunction with Jo who wanted to run a cheap and simple self contained local network to access his AIS's data from anywhere on his yacht. This resulting module creates an Access Point (a Router) and sets up a TCP server for up to 4 connections and also broadcasts the data on a UDP broadcast group. A configuration webpage is provide to set the TCP and UDP port numbers, the WiFi Tx power and the incoming RS232 baud rate. Unlike the WiFi Shield, there is no configuration button, so once constructed the module can be completely sealed water tight. Protection circuits are include to make this device robust against miss-wiring. While designed with NMEA (GPS) and AIS in mind, the module will handle any RS232 data with baud rates between 4800 and 38400 (and others by editing the Arduino sketch).

This project is also available on-line at Cheap NMEA/AIS Hub

Features

Uses the inexpensive and readily available ESP8266-01 module :- Other ESP8266 modules can also be used

Robust :- The circuit has a number of protections built in to guard against mistakes when wiring up.

Power Efficient :- A DC-DC converter power supply efficiently powers the unit from a 12V battery and the WiFi Tx power can be reduced to save more power.

Simple to use :- Just connect a 5.5V to 12V supply and the RS232 TX line and then join your receiver to the network and connect to the TCP or UDP service to receive the data. Can be quickly swapped for a spare one if the unit fails

Simple to configure :- There is no re-programming necessary, no special configuration mode. A configuration page is provided which allows you to set the RS232 baud rate and the WiFi transmit power and the port numbers for the TCP and UDP servers

Optional No config version :- There is also another sketch where all the config is pre-programmed. This is for those situations that already have a local network running with its own router (Access Point)

Supplies

This ESP8266-01 RS232 to WiFi Bridge needs the following parts, or similar. The prices shown here are as at August 2020 and exclude shipping costs and some sort of plastic case :-

WiFi Module ESP8266-01 – ~US$1.50 online (take your chances) OR for reliable product SparkFun ESP8266-01 – US$6.95

MPM3610 3.3V Buck Converter Adafruit – US$5.95 5V to 21V input, OR DC-DC 3A Buck Step-down Power Supply Module online Aliexpress ~US2.00

10-pin header Element14 – US$0.40 (or 28 Pin Header Terminal Strip from Jaycar AU$0.95)

1 off 1N5711 Schottky Diode Digikey US$1.15 (or Jaycar AU$1.60)

2 off 1N4001 Diodes SparkFun US$0.30 (or 1N4004 Jaycar AU$1.00) Any 1A 50V or higher diode will do, eg 1N4001,1N4002,1N4003,1N4004

1 off 2N3904 NPN transistor SparkFun US$0.50 (or Jaycar AU$0.75 any general purpose NPN with Vce > 40V, Hfe > 50 at 1mA, Ic > 50mA e.g. BC546, BC547, BC548, BC549, BC550, 2N2222

6 x 3K3 resistors e.g. 3K3 resistors – Digikey – US$0.60 (or 3K3ohm 1/2 Watt 1% Metal Film Resistors – Pk.8 from Jaycar AU$0.85)

3 off 330R resistor Element14 US$0.10 (or 330ohm 1/2 Watt 1% Metal Film Resistors – Pk.8 from Jaycar AU$0.85)

1 off 10K resistor Element14 US$0.05 (or 10k Ohm 0.5 Watt Metal Film Resistors - Pack of 8 from Jaycar AU$0.85)

Vero board (links and bus rails) Jaycar HP9556 OR (strip copper) (strip copper) e.g. Jaycar HP9540 ~AU$5.50

and a plastic case and hookup wire.

Total Cost ~US$9.90 + shipping and plastic case (as of August 2020) using Aliexpress ESP8266-01 and DC-DC module OR ~US$19.30 using Sparkfun ESP8266-01 module and Adafruit DC-DC buck converter. Cheap enough to make a couple of spares.

To program the RS232 to WiFi Bridge, you also need a USB to Serial cable. Here a SparkFun's USB to TTL Serial Cable (US$10.95) is used because it has nicely labelled ends and has driver support for wide range of OS's Including the programming cable, the cost for just one RS232 to WiFi Bridge is ~US$20 to US$24 (plus shipping and a case).

Step 1: Circuit Diagram and Circuit Protections

Above is the circuit diagram for the RS232 to WiFi Bridge (pdf version). This has been adapted from the ESP8266-01 Wifi Shield and modified to accept RS232 and a 5V to 12V (battery) supply. The DC to DC converter provides power efficient operation from a 12V battery for night time use when there is no solar power and power usage is at a premium.

A number of circuit protections have been built into the circuit. The connections on the left hand side of the circuit are only used during construction to program/debug the unit. The 330R resistors R6 and R7 protect against shorting a TX output to a TX output when programming/debugging. When programming you connect TX to RX and RX to TX. The debug TX output should be connected to an RX UART 3v3 input to see the debug output (see the comments in the ESP8266_NMEA_BRIDGE.ino sketch).

The connections on the right hand side of the circuit are used to connect the completed unit to the power supply and the NMEA/AIS RS232 source. These are the only connections that need to be accessible once the unit is built. Keep these connections in pairs.

The 2N3904 provide the inversion and level shifting from the RS232 +/-15V signal to the TTL UART input to the ESP2866. The reverse voltage between the Emitter and Base of the 2N3904 is specified to withstand at least 6V. The D4 limits the reverse Emitter Base voltage to be less than 1V when the the RS232 input is -15V.

Finally, “RS-232 drivers and receivers must be able to withstand indefinite short circuit to ground” (RS232 wikipedia) so if you accidentally connect the RS232 lines to the Power Supply terminals, it should not damage the NMEA/AIS device.

Power Supply

The diode D1 prevents reverse voltage being applied to the DC-DC converter if you happen to swap the +V and GND connections when wiring up. D1 has a small leakage current. D2 provides a low voltage path for that leakage current to keep the reverse voltage on the DC-DC converter below -0.3V. The 330R resistor (R10) in the RS232 GND line provides protection against shorting the battery to ground if the battery +ve lead is connected to the board's Power Supply GND wire while the RS232 GND is connected.

The DC-DC converter is rated for up to 21V operational input so it is suitable for a 12V battery while it is being rechanged. A battery on full charge can be up to ~14.8V and the charger voltage can be higher, 16V or more. The 21V input rating of the DC-DC converter is rated to handle this. Accidental reverse supply connection (in the middle of the night in rough weather) is protected against. The absolute maximum voltage for the converter input is 28V an so can handle have an RS232 signal connected to it. RS232 voltage is specified to be less than +/- 25V.

If you accidentally connect the leads from your power supply to the RS232 TX/GND connections (either swapped or not), the 10K and the 330R resistors will protect against shorting out the power supply.

In summary the circuit is protected against swapping power and RS232 leads and connecting the wires from those pairs in either way around. Mixing up wires, one from each pair, is not protected against in all combinations so keep the RS232 and power leads paired and connect them in pairs.

The average current used by the board is about 100mA (depending on the WiFi transmit power and data rate). If a simple linear regulator was used to power the board from a 12V battery the power usage would be 12V x 100mA = 1.2W or 1.2Ahrs over a 12 night. Using the DC to DC converter, which ~70% efficient, reduces this load to 0.47W or 0.47Ahrs over a 12hr night.

Step 2: Construction

I constructed this unit using a small piece of vero board with links and power buses (pdf version). Here are the top and bottom views of the completed board. Make sure you carefully check the wiring when you are finished. It is easy to wire to the wrong pin when you turn over and wire from the bottom.

Step 3: Programming the WiFi Shield

Each RS232 to WiFi bridge needs to be programmed once, only, and never again. A built-in webpage provides access to the available configurations.

Installing ESP8266 support

To program the shield follow the instructions given on https://github.com/esp8266/Arduino under Installing With Boards Manager. When opening the Boards Manager from the Tools → Board menu and select Type Contributed and install the esp8266 platform. This project was compiled using the ESP8266 version 2.6.3. Later versions may be better but may have their own bugs as the platform is evolving rapidly.

Close and re-open the Arduino IDE and you can now select “Generic ESP8266 Module” from Tools → Board menu.

Installing supporting Libraries

You also need to install, from https://www.forward.com.au/pfod/pfodParserLibraries/index.html, the latest versions of pfodESP8266BufferedClient library (for pfodESP8266Utils.h and pfodESP8266BufferedClient.h) and millisDelay library (for millisDelay.h).

Download these zip files to your computer, move it to your desktop or some other folder you can easily find and then use Arduino IDE menu option Sketch → Import Library → Add Library to install them. You also need to install the SafeString library. The SafeString library is available from the Arduino library manager or you can download the SafeString.zip file directly for manual installing via Sketch → Import Library → Add Library

Stop and restart the Arduino IDE and under File->Examples you should now see pfodESP8266BufferedClient and SafeString.

Programming the Board

To program the board, set the board into programming mode by shorting the link (bottom left). Then connect the USB to TTL UART serial cable

Note carefully only connect 3V3 TX/RX leads to the left hand side connection using the 3V3 TX/RX from Sparkfun's USB to TTL Serial Cable The cable connections are RX (Yellow), TX (Orange), VCC (5V) (Red), and GND (Black). Note the Yellow (RX) cable is connected to the TX pin on the board and the Orange (TX) cable is connected to RX pin on the board. The Black (GND) cable is connected to the GND for TX/RX pin.

Note: There seem to be two versions of this cable. Older versions have 5V Vcc and RX (Brown), TX (Tan-like/Peach), VCC (Red), and GND (Black), in any case the VCC lead is not used here. There are also comments that the TX and RX wire are reversed in some cases. If the Arduino IDE cannot program the board, try swapping the TX/RX cables. The 330R protects against TX-TX shorts.

Power the board from a 6V to 12V 500mA or larger supply or battery. Connect the Power supply -Ve (GND) lead first so that the power supply current does not try to flow back through the USB connection. Preferably use an isolated (floating) 6V to 12V supply or battery. Note the Aliexpress DC-DC modules need at least a 6.5V supply.

Then plug in the USB cable to your computer. Select its COM port in the Tools → Port menu. Leave the CPU Frequency, Flash Size and Upload Speed at their default settings.

Check the photo and your wiring. Also see ESP8266 Programming Tips (espcomm failed)Compile the ESP8266_NMEA_BRIDGE.ino sketch. Then select File → Upload or use the Right Arrow button to compile and upload the program. Two files are uploaded. If you get an error message uploading check your cable connections are plugged in the correct pins and try again.

Once the programming is completed, remove the programming mode shorting the link and the programming TX/RX connections and then turn the power supply off and on to restart the board in its normal mode.

Connect the NMEA/AIS device. NOTE: This ESP8266 Access Point does NOT provide
an DHCP service so you need to set a static IP in your receiving device (iPad/computer, etc). Because the ESP8266_NMEA_BRIDGE.ino sets up a network starting at 10.1.1.1, the static IP you set needs to be on the range 10.1.1.2 to 10.1.1.254. Each device needs its own unique IP

No Configuration Version

There is another version of this sketch, ESP8266_NMEA_BRIDGE_noCfg.ino, in which all the configuration is pre-programmed in the sketch code. In this case the NMEA hub connects to an existing router (access point) to make the data available to the network.

The configuration is all at the top of the ESP8266_NMEA_BRIDGE_noCfg.ino file.

Usually your router will support DHCP and automatically allocate IPs to your other devices. You must make sure the ESP8266_NMEA_BRIDGE_noCfg IPAddress staticIP setting does not duplicate an existing IP on your network. Setting an IP in the upper range x.x.x.200 to x.x.x.254 will usually be safe.

// =================  HARD CODED CONFIG ==================
const char ssid[] = "yourRouterSSID";   // set your network's SSID here
const char password[] = "yourRouterPassword";  // set your network's password here
IPAddress staticIP(10, 1, 1, 190); // set NMEA hub static IP here. NOTE the , between the numbers
// make sure no other device is running with this same IP and that the IP is in your router IP range
// common router IP ranges are 10.1.1.2 to 10.1.1.254
//  192.168.1.2 to 192.168.254.254 and
//  172.16.1.2 to 172.31.254.254
// the router is usually 10.1.1.1 or 192.168.1.1 or 172.16.1.1 depending on its range
IPAddress udpBroadcaseIP(230, 1, 1, 1);  // set the UDP broadcast IP here. NOTE the , between the numbers. This IP is independent of the router range do not change
const uint16_t tcpPortNo = 10110;  // set NMEA tcp server port No here
const uint16_t udpPortNo = 10110;  // set NMEA UDP broadcast port No here
const unsigned int txPower = 10; // TX power in range 0 to 82;
const unsigned int GPS_BAUD_RATE = 4800;  // the Serial baud rate of you GPS module
// ================= END OF HARD CODED CONFIG ==============

Step 4: Adding Indicator Leds (Optional)

My sailing consultant on this project, Jo, suggested mounting a Red Power led and a Green Data led on the case to indicate that things are running. Here is the modified circuit with these two leds added. (pdf verison)

R9 and R11 set the Led current and hence the brightness. Use the largest resistor that makes the leds still visible. They will be difficult to see in direct sunlight or in a bright cabin, so mount the unit in a dark corner for maximum visibility. Jaycar has suitable bezel leds Red and Green (~AU$2.75) and Sparkfun has some super bright Red and Green leds (US$1.70) but almost any red and green led will do.

Step 5: Setting the Configuration Via the Built in Webpage

When you power up the board after programming, it will automatically create a local network. That is it will become a local Access Point (router). The network name will start with NMEA_ followed by 12 hex digits unique to each board, eg. NMEA_18FE34A00239 The password for the local network is always NMEA_WiFi_Bridge. If you need to swap units at sea, power down the old one, install the spare and then look for the new NMEA_..... network and use the password NMEA_WiFi_Bridge to join it.

If you cannot see the network, move closer to the circuit board and check that you have the power cables connected correctly. There should be a blue light one the ESP8266-01 board.

Once you have joined the network with your computer, or mobile phone, you can open the configuration webpage at http://10.1.1.1 (Note: type in http://10.1.1.1, if you just type in 10.1.1.1 you may get Google trying to search for it and failing since you are not connected to the internet). If the page is not found, check that you have set a static IP on your computer/mobile in the range 10.1.1.2 to 10.1.1.254.

The configuration page lets you set the WiFi transmit power. Lower numbers for less power and range and current consumption. You can also change the port numbers for the TCP and UDP connections. The default 10110 is the designated port for NMEA connections, but you can choose your own if you wish. The IP numbers are fixed. Finally you can set the baud rate to match your NMEA/AIS source. 4800 baud is the standard baud rate for NMEA. While 34800 baud is the standard baud rate for AIS.

Once you have made your selections, click Submit and a summary page of the changes that have been stored is shown.

If these are not correct then use the browser back button to go back and fix them. To apply the changes the board needs to be restarted. Clicking the Apply these change button will do that.

Once the board restarts it will automatically show the configuration page again with the current configuration.

Connect your computer or mobile device to either the TCP or UDP connection and check you are getting data.

That's it finished!! Seal every thing up in a water tight plastic box leaving only the two power leads and the two RS232 leads free.

Step 6: Help – No Data

Once you have connected to the network and set your mobile device to connect to the TCP 10.1.1.1 and the port you have set (or join the UDP multicast group 230.1.1.1 with the port you have set), if you still do not get any data try the following steps.

1) Check the NMEA / AIS equipment is turned on

2) Check the RS232 cables are connected the right way around.

3) Check the 'flow control' setting on your NMEA / AIS equipment. Set it to 'NONE' if that is an option. If not then choose 'hardware' OR RTS/CTS flow control and short out the RTS to CTS and DSR pins of the NMEA / AIS cable. That is for a DB-25 connector, connect pins 4 and 5 and 6 together. For a DB-9 connector, connect pins 6 and 7 and 8 together. With 'hardware' control the NMEA / AIS equipment (the DTE) asserts RTS (ReadyToSend) when it wants to send data. With these connections the RTS pin drives the ClearToSend (CTS) and DataSetReady (DSR) pins which are input back into the NMEA / AIS equipment to tell it that the other side is ready and able to receive data.

4) By default the Bridge supplies an IP to your device via DHCP in the range 10.1.1.100 to 10.1.1.200. However if you cannot connect to the config webpage on 10.1.1.1 or cannot receive any data, you may need to manually set an IP in the range 10.1.1.2 to 10.1.1.99 on your computer/device. Also check if you have a manual static IP set for some other network range and if so change to a static IP in the range 10.1.1.2 to 10.1.1.99

Debugging

To turn on the Debugging TX output, uncommenting, i.e. edit to
#define DEBUG
near the top of the ESP8266_NMEA_BRIDGE.ino sketch.

Remove the TX/RX USB cables and just connect the Yellow RX cable to the Debug TX output. Leave the Black GND cable connected to GND for TX/RX. The Arduino IDE Serial Monitor will now show debug messages.

By default the UDP multicast group is started, but you can disable it by commenting out, i.e. edit to
// #define UDP_BROADCAST
near the top of the ESP8266_NMEA_BRIDGE.ino sketch.

Conclusion

This NMEA/AIS RS232 to WiFi bridge is robust and simple to use. It efficiently runs from a 12 battery source and is cheap enough to carry a spare with you that you can swap in mid voyage if necessary.

2 People Made This Project!

Recommendations

  • On a Budget Challenge

    On a Budget Challenge
  • First Time Author Contest

    First Time Author Contest
  • Eggs Challenge

    Eggs Challenge

44 Comments

0
wildwilliam
wildwilliam

Question 1 year ago

OK, so I uploaded the sketch to the ESP8266 successfully, I can see the WiFi network, I can connect to it but I don't get an IP address for my computer so I cannot go to http://10.1.1.1 because my computer doesn't have a network address. It seems it is not providing a DHCP address to my machine.

What am I missing?

0
drmpf
drmpf

Answer 1 year ago

Try manually setting an IP for your computer say 10.1.1.100
Worked for me, but my local network is normally 10.1.1.xx so that may be the difference.

0
wildwilliam
wildwilliam

Reply 1 year ago

Yeah, I finally figured this out about 30 minutes before you suggested it :-) Setting my PC to a static IP of 10.1.1.10 did the trick.

Any idea how to get the AP to act as a DHCP server as well?

0
drmpf
drmpf

Reply 1 year ago

Sorry I have not used the ESP8266 as a DHCP server. A quick web search did not show up any simple example code, but suggests it is supported by the SDK

0
drmpf
drmpf

Reply 7 months ago

Yes there is DHCP and I have enabled it now (10.1.1.100 to 10.1.1.200) so that should solve your and similar problems. However on one computer here I still had to manually set a static IP in the range 10.1.1.2 - 10.1.1.99

0
drmpf
drmpf

Tip 8 months ago

Update 11th Jan 2022 – Added DHCP and note about static IP's in Step 6 Help - No Data

0
Navchetan Singh
Navchetan Singh

8 months ago

Good day, It is an amazing project for sailors like me. I am thinking to build one but i am would like to use node mcu (esp8266cp2102) for this project so that i can power from any usb adaptor and plug rs232 cables to pilot plug. I have one query on node mcu where should i connect rx pin after the 2N3904? Is GPIO3 RXD0. Thanks in Advance.

9A44A8A8-69B1-48FC-A5C6-6AA6A3E64898.jpeg
0
drmpf
drmpf

Reply 8 months ago

Here is a modified circuit for ESP8266 boards that run from USB 5V and have reset/program and pullup resistors fitted already.
Match the pin names to your board's diagram.
Rx is GPIO3 (RXD0)

Vin is Vin (5V / USB)

3V3 is 3V3

GPIO2 is GPIO2 (TXD1) not necessary unless you need to debug the code

You can power this circuit either via a USB 5V supply OR via the 5V version of Adafruit's MPM3610 (product No 4739)
BUT DO NOT connect both the USB and the Power Supply Connection at the same time!!

NMEA_mcu.jpg
0
papamaik
papamaik

Question 1 year ago

Hi
With this IP and Subnet I am able to open the configuration page, but I cannot receive some data on OPENCPN.
in my tests I use the Matsutec HA 102 AIS Trasponder, however even using an Nmea simulator I can’t get any data.
Can you help me?
Ty

IMG_8892.JPGIMG_8893.JPG
0
drmpf
drmpf

Answer 1 year ago

Make sure the RS232 baud rate is correct. Connect the debug output TX to a TTL to USB cable to see what is arriving at the bridge.
I am not a sailor so perhaps someone else here can help with OPENCPN, but check the connection setting for IP and data port match what is set in the bridge config. NOTE: the IP address is fixed in the bridge so the OPENCPN must be changed to match that. The port numbers also need to match.

0
papamaik
papamaik

Reply 1 year ago

connecting the debug output displays the one attached. both in the presence and in the absence of data traffic.
the port and connections are correct.
Do you have any suggestions?

IMG_8895.JPG
0
drmpf
drmpf

Reply 1 year ago

OK that says nothing is connected to receive TCP/IP, and there are no UDP broadcasts. So to receive some data you need to connect something to 10.1.1.1 port 10114
Also
Try adding some debug output to for the serial input msgs to see if any data is arriving on the RS232 (NOTE: the input is RS232 NOT TTL Serial)
In ESP8266_NMEA_BRIDGE.ino edit the sketch as shown below near line 335

// handle input
// read into SafeString until get <cr><lf> terminator
// filter (to be done)
// write out to TCP and UDP
if (NMEAstr.readUntil(SerialGPS, "\n")) { // non-blocking read
// found \n in input so process line
bool endsWithNL = NMEAstr.endsWith("\n");
NMEAstr.trim(); // remove leading and trailing white space
if (!NMEAstr.isEmpty()) { // skip empty lines
if (endsWithNL) {
NMEAstr += "\r\n"; // add back <CR><NL> terminators
} // else just buffer full
// >>>>>>>>>>>>>>>>>>>> add debug here >>>>>>>>>>>>>
if (debugPtr) {
debugPtr->print(NMEAstr);
}
//
>>>>>>>>>>>>>>>>>>>> debug end >>>>>>>>>>>>>

0
papamaik
papamaik

Reply 11 months ago

hi drmpf
I finally managed to connect with Navionics as well. however, even by setting the tx Power to 80/82, the WiFi output signal is very weak and in any case it is lost if the distance from the Bridge exceeds 1 meter. I tried to add an 8cm antenna too but with no results.
Can you help me?

IMG_8922.jpg
0
drmpf
drmpf

Reply 11 months ago

Not sure what is happening there. That range seems very short. I have not had any other reports of this. The extra wire antenna may not be helping at all.
Do make sure your power supply can provide 500mA to the ESP8266.

You can increase the WiFi range by adding your own router, next to the bridge.
Use the ESP8266_NMEA_BRIDGE_noCfg.ino sketch, with appropriate ssid and pw, so that the bridge now bridges between RS232 and your own router. Your other devices now connect to the router's higher power network.

0
papamaik
papamaik

Reply 11 months ago

Hi drmpf
there are no current limits on the power supply, however the consumption of the Bridge does not exceed 90 mA. ??
is there some problem in the sketck on setting of the TxPower?

0
drmpf
drmpf

Reply 11 months ago

The power requirements come in short bursts during Transmit.
No problems with the TxPower setting I am aware of.

0
drmpf
drmpf

1 year ago on Step 3

Update 9th August 2021 – Fixed links to pfodESP8266BufferedClient library

0
papamaik
papamaik

Reply 12 months ago

hi drmpf
i finally managed to connect my transponder to the navionics app through the bridge.
Thank you for your help

0
drmpf
drmpf

Reply 12 months ago

What the trick that made it work for you?

0
papamaik
papamaik

Reply 12 months ago

hello drmpf
ok
now I can get the bridge to work with the OPenCpn navigation program; however I cannot connect with the Navionics app.
there is talk of another IP address and port 2000 but I can't set them on the tablet.
anyway thanks