Skip to content

Commit a565976

Browse files
committed
compatible with Arduino IDE 2.0
+ Auto install dependencies + update MQTT example
1 parent 18153a2 commit a565976

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ Open a TCP connection to a server from the Arduino using just serial. No Etherne
55
Quickly communicate with other servers and make network apps using minimal hardware.
66
See [this](https://github.com/RoanBrand/SerialToTCPBridgeProtocol) for more information on the protocol and for the **Protocol Gateway** you will need to run on the host PC the Arduino is connected to serially.
77

8-
## Requires:
8+
## Hardware Requirements:
99
- Serial 0 (Main serial through USB)
1010
- Timer 1
1111

1212
## Dependencies
13-
- [NeoHWSerial](https://github.com/SlashDevin/NeoHWSerial) - Install manually
14-
- [CRC32](https://github.com/bakercp/CRC32) v2.0.0 - Can be installed from the Arduino *Library Manager*
13+
- [NeoHWSerial](https://github.com/gicking/NeoHWSerial) v1.6.6
14+
- [CRC32](https://github.com/bakercp/CRC32) v2.0.0
15+
- [PubSubClient](https://github.com/knolleary/pubsubclient) v2.8.0 - Needed for the included **MQTT Client Example**
1516

16-
After installing the dependencies and this library, make sure you have all 3 present inside your **libraries** sub-directory of your sketchbook directory.
17+
These should install automatically when installing this library through the Arduino *Library Manager*.
1718

1819
## How to
1920
- Get the [Protocol Gateway](https://github.com/RoanBrand/SerialToTCPBridgeProtocol) and build it.
20-
- Change the gateway's config to listen on the COM port connected to your Arduino and start it.
21+
- Change the gateway's config to listen on the Serial port connected to your Arduino and start it.
2122
- Your Arduino app can then use the `ArduinoSerialToTCPBridgeClient` API which is similar to the `EthernetClient` API to make tcp connections to servers as long as they are reachable from the host PC and the gateway service is running.
2223

2324
## Web Client Example
@@ -28,12 +29,12 @@ After installing the dependencies and this library, make sure you have all 3 pre
2829
- On other boards with more hardware serial ports than the Uno the example can be modified to use those instead (Serial1,2,etc.) and remove the software serial lib.
2930

3031
## MQTT Client Example
31-
1. Install [PubSubClient](https://github.com/knolleary/pubsubclient) - Manually, or from the Arduino *Library Manager*.
32-
2. Get a MQTT Broker running on your host PC, listening on `localhost`. I used [HiveMQ](www.hivemq.com).
33-
3. Open and upload the example from the Arduino *Examples menu*.
34-
4. Run the **Protocol Gateway** on the same PC, with the right COM port configuration.
35-
5. When the Arduino is connected to the MQTT broker, it will publish a message and subscribe to the `led` topic.
36-
6. You can use another MQTT client like [MQTT.fx](http://mqttfx.jfx4ee.org) to publish characters `0` and `1` to the topic `led` to toggle the led on and off on the Arduino board.
32+
1. Open and upload the example from the Arduino *Examples menu*.
33+
2. Run the **Protocol Gateway** on the same PC, with the correct Serial port configuration.
34+
3. After a short time, the Arduino should connect to the MQTT broker `mqtt.eclipseprojects.io`.
35+
4. Using a MQTT client, like [MQTTX](https://mqttx.app/), connect to the same broker and subscribe to the `ArduinoOut` topic.
36+
5. While the Arduino is connected to the MQTT broker, it will publish a message to the `ArduinoOut` topic every 5s.
37+
6. Using the client, publish characters `1` and `2` to topic `LedIn` to toggle the led on and off on the Arduino board.
3738

3839
### Details
3940
- Tested only on Arduino Uno. It would probably not work for the Arduino Due.

examples/MQTTClient/MQTTClient.ino

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/*
22
* Basic example of MQTT Client running over the Serial To TCP Bridge Client.
33
*
4-
* The example connects to a Broker serving on "localhost" on the host PC.
5-
* It will publish millis() as a message every 5s, while connected.
4+
* It uses the MQTT client package PubSubClient from Nick O’Leary.
5+
* Install it from the Library Manager, if not already automatically installed.
66
*
7-
* Using another MQTT client:
8-
* Publish char '1' to topic "led" to turn on Led on Arduino Uno and '2' to turn off.
7+
* The example connects to the public Broker at "mqtt.eclipseprojects.io".
8+
* It will publish millis() as a message every 5s to topic "ArduinoOut", while connected.
9+
*
10+
* Using a MQTT client (e.g. https://mqttx.app):
11+
* Publish character '1' to topic "LedIn" to turn on the Led on the Arduino Uno and '2' to turn it off.
912
*/
1013

1114
#include <ArduinoSerialToTCPBridgeClient.h>
@@ -14,8 +17,8 @@
1417
ArduinoSerialToTCPBridgeClient* s; // Protocol Client running over USB Serial
1518
PubSubClient client; // MQTT Client
1619

17-
const char* broker = "localhost";
18-
const char* ledTopic = "led";
20+
const char* broker = "mqtt.eclipseprojects.io";
21+
const char* ledTopic = "LedIn";
1922
const char* outTopic = "ArduinoOut";
2023

2124
uint32_t lastPub = 0;
@@ -68,7 +71,7 @@ void callback(char* topic, byte* payload, unsigned int length) {
6871
boolean connectToBroker() {
6972
if (client.connect("arduinoClient")) {
7073
// Publish first message on connect and subscribe to Led controller.
71-
client.publish(outTopic, "Hello world!");
74+
client.publish(outTopic, "Arduino connected!");
7275
client.subscribe(ledTopic);
7376
return true;
7477
} else {

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name=ArduinoSerialToTCPBridgeClient
2-
version=1.1.0
2+
version=1.1.1
33
author=Roan Brand <brandroan@gmail.com>
44
maintainer=Roan Brand <brandroan@gmail.com>
5-
sentence=Open a TCP connection to a server from the Arduino using just serial. (No Ethernet/WiFi shields necessary)
6-
paragraph=Quickly communicate with other servers and make network apps using minimal hardware. INSTALL DEPENDENCIES! The Protocol Gateway service runs on the host, listens on a COM port connected to the Arduino, and opens TCP connections on behalf of the Protocol Client runnning on the Arduino, forwarding traffic bi-directionally. The protocol provides the app an in order, duplicates free and error checked byte stream by adding a CRC32 and simple retry mechanism.
5+
sentence=Open a TCP connection to a server from the Arduino using just Serial. (No Ethernet/WiFi shields necessary)
6+
paragraph=Quickly communicate with other servers and make network apps using minimal hardware. The Protocol Gateway service runs on the host, listens on a Serial port connected to the Arduino, and opens TCP connections on behalf of the Protocol Client runnning on the Arduino, forwarding traffic bi-directionally. The protocol provides the app an in order, duplicates free and error checked byte stream by adding a CRC32 and simple retry mechanism.
77
category=Communication
88
url=https://github.com/RoanBrand/ArduinoSerialToTCPBridgeClient
99
architectures=*
1010
includes=ArduinoSerialToTCPBridgeClient.h
11-
depends=CRC32
11+
depends=CRC32 (=2.0.0), NeoHWSerial (=1.6.6), PubSubClient (>=2.8.0)

0 commit comments

Comments
 (0)