March 27, 2024  New product: Python Gateway

Unbelievable, but true: all the power of Python 3 can run on the same power as three standard 3mm LEDs and convert AIS messages from NMEA 0183 to NMEA 2000 in just 1.5 milliseconds. We are proud to present the most fun product for installers, developers and NMEA hackers!

Python Gateway unboxed

If you want to see how it works right away, click into this example. In ten lines of code, we've created a virtual depth sounder that uses data from a real sounder and tweaks it a bit. Why it's needed? For example, the display that came with the echo sounder broke and you can't adjust the transducer offset. With these 10 lines of code, we manage to turn our Gateway into an echo sounder type device so that we can select it in the lists of data sources on the multifunctional display and give it a description that will be visible on the MFD. Moreover, the sounder we created is NMEA 2000 compliant and handles all the necessary messages.

If you are an experienced programmer and are familiar with the CAN interface and the microcontroller you are writing the code for, it will take you a week to write and debug such code in C language. If you don't believe us, ask programmers. They will tell you that it will take at most three days, but it will take at least a week. Most likely two or even three, because to comply with the Standard, you need to implement support for more than a dozen of service messages (it is not visible in the example code), and some of them are not simple.

How do you run this code on your Python Gateway? Very simple. You connect it to the PC via USB, open the disc, open the file on the disc in any text editor, and paste the example code into it. Save, reboot the device and you're done.

Thonny IDE with voltmeter code

Picture 1. Thonny IDE with voltmeter code

But even better is to download the Thonny IDE. It's a free open-source development environment that allows you to edit files directly on your device, start and stop your program, view variables, highlight syntax, etc. It's just great! And it doesn't work through the disc, but through the console. When connected via USB, Python Gateway provides two USB devices at the same time: a disc and a serial port on which the Python interpreter (REPL) is running. Thonny can read and write files, and receive data from the device via a terminal session.

Terminal session with Python Gateway

Picture 2. Terminal session with Python Gateway

But of course, you can connect to the device with a good old-fashioned terminal. Type the command can.test() and ten messages received from the CAN bus will appear on the screen. It will look just like in a hacker movie, especially if your terminal has green colored characters.

If you are not a programmer or a hacker, of course, even a simple programming language and a great library for NMEA will not make your job much easier. But, in our experience, many tasks can be solved with just a few lines of code. So if you think that our product can help you, write to us, and if the task is really a few lines, we will write you the code absolutely free of charge.

In addition to USB and CAN (NMEA 2000), the product has two hardware serial ports (NMEA 0183). More precisely, two halves of two ports, as one port is only for receiving messages and the other only for transmitting. This is so that you can connect two devices at different speeds (e.g. 4800 and 38400 baud) and organize a gateway between them. The serial port has a high voltage galvanic isolation from the USB and CAN interfaces.

The implementation of serial ports has various tricks, such as inverting lines. This allows to connect not only standard RS-422A (NMEA 0183) devices, but also different exotic things. For example, Python Gateway can read B&G FastNet and Raymarine SeaTalk 1 buses, we will publish code samples soon.

As you might already know, we have the NMEA 2000 Bridge, this is a gateway between two CAN networks with its own built-in programming language for message handling. Most of the sales of these devices come from partner companies who produce their own gateways based on them for various scenarios, ranging from a simple data filters to a custom electrical propulsion telemetry and control systems.

In the Python Gateway, we have provided encryption and source code protection from copying and viewing. At the end of April we plan to publish a guide to creating and distributing secure code, which will allow companies to create closed solutions where required to comply with commercial, copyright or non-disclosure obligations.

Our product is based on code from the popular MicroPython project, which adapts Python 3 for microcontrollers. And, of course, we cannot boast the same power and richness of libraries that personal or even single-board computers such as Raspberry Pi can offer. Nevertheless, our Gateway does an excellent job of performing the tasks for which it was created.

As an example of a complex task, we have implemented an AIS converter from NMEA 0183 to NMEA 2000. Here we need to decode binary messages transmitted in NMEA 0183 envelope, convert the data into NMEA 2000 units, and package them into NMEA 2000 messages. The messages themselves look like this in NMEA 0183:


It takes 1.5 milliseconds to process such a message, allowing this converter to easily operate in real time, as the 38400 baud connection can transmit less than 80 messages per second. The unit consumes 32mA only, which is equivalent to the current of three small LEDs such as those installed on the unit itself. When transmitting over NMEA 0183, the current with maximum load can rise up to 68 mA.

To start getting familiar with the product, go to its page or the Programming Manual page. Once you start using it, you will be fascinated by it, we assure you! If you have already received your device, download firmware update 1.02 from the Download section.


Next articles:

Previous articles:

See also: recent news, all news...