mqtt serial message without ethernet - arduino

everywhere I look, if it comes to MQTT messaging, it is all over Ethernet. Unfortunately, I do not have Ethernet wires available.
I am automating my home, wanting to use mqtt as messaging service. My buttons give a signal (like light 'on') to an arduino board running a mqtt client. How do i put out the mqtt message on the serial lines so the transmitted message can be straight forwardly be picked up by an mqtt broker, without using the ethernet cables?

As I was looking for the same answer and didn't find anything to my liking, I decided to write an implementation that enables any Bluetooth, USB or pure serial port communication to send MQTT message. You can find the result here : https://github.com/vortex314/serial2mqtt
It enables any linux machine ( Raspberry Pi 1, Raspi 3 , PC ) to act as a gateway.
It's written in C++ so should be lightweight enough for small devices.
Hope this helps.
Update 27/6 : build folder contains pre-build version for Linux Intel and Raspberry.

I am trying to achieve similar goals for my house automation, although I do have Cat5e in the walls, so could use Ethernet.
Here are some possibilities for using MQTT over serial communication:
Use SLIP between the Arduino and the gateway. The SerialIP client library which implements TCP/IP over serial: http://playground.arduino.cc/Code/SerialIP . Although I have not tested if this works with a MQTT client library. Nick O'Leary's MQTT Client theoretically works with any implementation of the Arduino 'Client' class.
It may be possible to implement MQTT directly over serial, without TCP/IP, although I am not aware of any gateways to do this.
MQTT-SN (a slightly different protocol to MQTT) was designed for sending messages over unreliable transport, and may be better suited to a serial line. If you are interested in publish-only, I wrote a very basic library to send MQTT-SN packets over serial: https://github.com/njh/DangerMinusOne
You could use something like Node-RED on the Linux gateway, talking some other serial protocol (Firmata?) to the Arduino and then converting to MQTT using Node-RED.
I did start looking at MQTT over serial implementations but one of the problems I didn't resolve was how to deal with multiple devices:
Adding lots of serial ports to Linux is complex/expensive (well sort of https://twitter.com/njh/status/570298977310150656)
Reliable serial over longer distances requires extra components for RS-485
MQTT doesn't work well over half-duplex, without an extra layer of software to deal with a master polling slaves for messages
So I am current looking at implementing MQTT-SN for the ENC28j60 ethernet controller...

For SLIP there is also the backwards compatible SlipMux which could easily support MQTT packet types. See also: sending packets over serial comms java
You could build a simple proxy that converts MQTT packets to SlipMux packets on one side and decodes the packets on the other side. The MQTT implementation should not notice anything.

Related

ESP8266 connection to a Arduino Nano

I am trying to connect a WiFi module (ESP8266) to a "funduino" development board (Arduino Nano) but I have no success. Since I tried so much schematics I've found on the internet about the connection between them two, I kindly ask here if is anyone who succeed in "pairing" this two devices.
I am asking for the schematic and a functional source code.
Regards
The ESP-01 by default comes with nonOS SDK bootloader that communicated via AT commands, you can find the complete command set from Expressif here. This is designed for an MCU (like Arduino Nano) to use it purely as an WiFi module rather than using it as a stand-alone MCU (for which it will require NodeMCU SDK).
If you ever upload an Arduino sketch up to the ESP-01, it will erase the AT Command firmware.
Assuming your ESP-01 is still having the AT Command firmware. What #Ben provided is a sketch that allows you to type AT commands via the Serial Monitor to internact with the ESP-01, it is manual, and good for testing if ESP-01 is working (you type AT and press return on Serial Monitor, the ESP-01 will ack with Ok) but not practical as a real application. The minimum commands required to established an WiFi connection with ESP-01 is listed below.
AT+CIPMUX=1 - Enable single (0) or multiple connection (1) to the web server.
Multiple connection is a good option if you are repeatedly sending
out or reading data from the Internet.
AT+CWMODE=3 - Set WiFi mode: 1 is station mode (ESP8266 is client), 2 is AP mode
(ESP8266 acts like a WiFi router where your phone or PC can connect),
3 is AP+station mode (make the ESP8266 do both)
AT+CWJAP=“<your-ssid>”,”<your-pw>” - Connect to your WiFi. Provide your SSID name
and password inside the double qoutes.
AT+CIFSR - This returns the IP address of the module, indicating that it has
successfully connected to your WiFi router.
Once the WiFi connection is established, you can further communicate with the ESP-01 via the connection, like accessing a website for example:
AT+CIPSTART=0,"TCP", "www.example.com","80” - Start TCP or UDP connection. The
0 is the id of the connection.
AT+CIPSEND=0,16 - Command to tell the module data is ready to be sent. 0 is the
connection id, and 16 is the length of the data to be sent.
After this command, the ESP8266 will reply with the “>”
character to tell us that it will be waiting for the data to be
sent. If successful, the module will reply with “SEND OK”
GET / HTTP/1.1 - Send the http header, and other data, etc...
You can write your own sketch to automate those AT commands for interacting with with ESP-01 once you understand the AT commands required for establish a WiFi connection.
Here are two resources that I personally found extremely useful for doing more than connecting to WiFi.
STM32-ESP-01 Web Server - although this is for interfacing with STM32, the main difference is the pin assignment, so you should be able to port to Arduino easily.
MQTT via ESP-01
As for hardware interface, please noted that what #Ben provided is correct in principle, but you need to be aware that the ESP-01(ESP8266 to be precise) is a 3V3 MCU, so the connection is depended on what kind of host board you are using. If you are using Arduino Uno/Nano, both are having a 5V MCU, you will need a voltage divider (two resistors to drop the voltage to 3v3 before connecting to ESP-01) or a level shifter chip at least for the ESP-01 Rx pin to avoid the potential damage to the ESP-01.

How to send internet packets between two Arduinos?

For a project I am working on, I am wondering if there is a way to send internet packets between two Arduinos.
The setup would be to have both Arduinos have ethernet shields. One shield is connected to a computer and the other to a router or other internet connection. The Arduinos need to communicate to each other relaying the packets of information. The goal is to be able to ping the router from my computer through these two Arduinos.
Any help would be greatly appreciated. Thank you.
there a mutliple ways of communication over the internet.
UDP library
Very easy and simple to use, but there is no validation if the packages received or not... (The Arduino library has a UDP class)
Using the client class
Arduino one is a server and Arduino 2 a client.
For example: one arduino sends a string/packet using server.print(data) the other receives it using client.read().

computer AND esp8266 WITH arduino

how the bellow connection can be done , what the protocol that must be used to send bytes from computer through it's serial WiFi and receive the bytes in Arduino using ESP8266-01 WiFi Serial Transceiver Module.
computer AND esp8266 WITH arduino
It depends on what you want to accomplish, and what roles you want the computer and the arduino/esp combi to play. You can put the ESP in station or access point mode (or mixed), and have it talk to the arduino via the serial interface. The communication with the PC will indeed go via wifi/tcp protocol, but depending on your specific requirements you will have to decide one the roles. Then you can make the ESP a web client or a web server, mainly depending on the direction of the flow of information.
I assume you want to query the Arduino from the PC, in which you can send a HTTP/GET request from the PC to a simple web server on the ESP.
There are various examples in the Arduino examples that do just that to give you a start, available when you install the ESP library in the Arduino IDE, see: https://github.com/esp8266/Arduino
HTH

Arduino ethernet communication

Is it possible to get sensor output from Arduino via Ethernet connection and to send data to Arduino via Ethernet?
So basically can "replace" serial port with Ethernet port?
The typical way to do this is with an Arduino Ethernet shield, a small hardware module that plugs into your Arduino board:
http://arduino.cc/en/Main/ArduinoEthernetShield
Updated:
One very common approach for client to server communication would be to use HTTP over TCP/IP. See this example on the Ardunio site of a simple client on an Ardunio connecting with a server (in this case google):
http://arduino.cc/en/Tutorial/WebClient
For your use case you can simply create your own server and modify the example to send data to it.
Alternatively you can skip the HTTP part and just use sockets - there is an open source example here:
https://github.com/billroy/socket.io-arduino-client

Can Cat 5 cable communicate with microcontroller and CPU?

So I was curious if this is possible at all. Currently i have a program running in a micro controller (digi rabbit) that reads SPI data from a chip. I also have TCP/IP protocol set in this program so it sends the SPI data to the server. Microcontroller is programmed in C. Server is in java. I convert SPI data into string and send it over, the server reads the raw data.
But i wanted to know if there is a way that I can read the data from Ethernet port. So what i want is one end of cat 5 cable on micro controller and the other on Ethernet port of the computer. Just for testing purposes that micro controller port and everything is installed properly, before i turn on the server. I am not that experienced with networking. So if anyone can point to a blog, or any tips that would be great. My question is how would i go about it?
Thank You
What you want to do is called raw Ethernet. Of course this can be done.
On the microcontroller side you need to follow its Ethernet controller datasheet to send out and receive packets. On the PC side this is a bit more complicated and depends on the OS that is running on the PC. On Windows you can use the WinPcap driver to send and receive raw Ethernet packets.
Be aware, that both Ethernet controllers, the one on the PC and the one on the microcontroller, filter all incoming packets that do not contain the receivers MAC address or any multicast/broadcast address. For a simple check the broadcast address (all address bits are 1) will do.
Also note, that the OS on your PC will transmit all kind of packets as soon as the link is established. So you may use a unique protocol identifier in the type field of your raw Ethernet frame. Check Wikipedia's article about Ethernet frames. Btw. don't get confused. You only need to send MAC-adresses, Ethertype and the payload. Everything else, like the CRC, preamble etc., is added by the Ethernet controller automatically.

Resources