There is a large class of tasks, called Internet-Of-Things when the hardware needs an Internet connection to send or receive data from some server. For example, log the temperature and moisture for smart greenhouses, getting the current time, weather, work with XOD Cloud or other APIs, and so on.
Some microcontrollers can access the internet on their own, like ESP8266, or with connected modules or shields, like W5500 ethernet shield or ESP8266 in AT-modem mode. But if you have a microcontroller without internet support or no microcontroller at all, XOD has a solution for you: use the xod/debug/tethering-inet
node to provide the internet from your PC to your microcontroller via UART or use it in the simulation.
The internet tethering feature uses low-level internet communication which is supported by OS but not available to the web-browser. So it only works in the desktop version of the XOD IDE.
To present the benefits of the internet tethering, we are going to take an example from the guide of HTTP GET request and modify it a little bit:
xod/debug/tethering-inet
node.xod/debug/watch
, to get rid of any hardware in the program.Try uploading this program in debug node or run its simulation. Wait for a little bit and you get your remote IP address in the watch node. The program works the same as in the example on your Arduino Uno (which does not have internet connectivity features at all), it works the same in the simulation.
Sending data to the internet works the same as getting data, but usually, it uses POST or PUT methods of an HTTP request. We took an example from the guide about XOD Cloud Feeds and modify it a little bit by replacing the connect
node with tethering-inet
.
This example gets values from a thermometer but if you have no thermometer or microcontroller at all, you can replace it with xod/debug/tweak-number
and change this value manually.
If you have signed in and ran the program, you’ll see temperature values in your feed.
The program communicates with the PC via the serial interface or virtual serial interface in case of simulation. The communication protocol is based on ESP8266 AT commands but uses fewer commands. For example, it does not provide a feature to switch between WiFi access points, because the PC should already have an established internet connection, which might be supplied by the ethernet cable.
Here is a sequence diagram, which illustrates a process of sending a request and receiving the response from the HTTP server:
The solid filled rectangles on the “Program” lifeline indicate that the process is synchronous, so it blocks the execution of the rest of the program. Meanwhile, the filled rectangles on the “PC” lifeline just group processes because the code on PC has its event loop. So you can still interact with the XOD IDE while PC transmitting some data either to the Internet or program. To emphasize this, the diagram uses two types of arrows: with the bold end to indicate synchronous messages and with thin ones for non-blocking messages. Dashed arrows indicate that these messages are responses for the previous.
OK
or ERR
. After that, the program loop is not blocked.>
. Then it sends a request line by line. When all request was sent or response SEND OK
received the program loop is not blocked anymore.ACK
command.EOT
command from the PC. It indicates that the response is end and connection is closed.After you wrote and test the program with the tethering-inet
node, you might want to use your device without a connected PC. It’s time to replace tethering-inet
with the suitable node for module or microcontroller, which you have at your hands.
And it will keep working, without PC at all.
xod/debug/tethering-inet
node.