Skip to content

Commit 7857510

Browse files
authored
Merge pull request #3 from RoanBrand/rb-name-change
Rb name change
2 parents a565976 + ce76b77 commit 7857510

File tree

8 files changed

+68
-43
lines changed

8 files changed

+68
-43
lines changed

LICENSE.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BSD 2-Clause License
2+
3+
Copyright (c) 2023, Roan Brand
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Arduino Serial to TCP Bridge Client
1+
# Arduino TCP over Serial Client
22
Arduino client for the [Serial To TCP Bridge Protocol](https://github.com/RoanBrand/SerialToTCPBridgeProtocol) gateway service.
33

4-
Open a TCP connection to a server from the Arduino using just serial. No Ethernet/WiFi shields necessary.
4+
Open a TCP over Serial connection to a server from the Arduino using the host. No Ethernet/WiFi shields necessary.
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

@@ -19,7 +19,7 @@ These should install automatically when installing this library through the Ardu
1919
## How to
2020
- Get the [Protocol Gateway](https://github.com/RoanBrand/SerialToTCPBridgeProtocol) and build it.
2121
- Change the gateway's config to listen on the Serial port connected to your Arduino and start it.
22-
- 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.
22+
- Your Arduino app can then use the `TCPOverSerialClient` 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.
2323

2424
## Web Client Example
2525
- Modified version of the Ethernet shield's Web Client example.
@@ -39,10 +39,10 @@ These should install automatically when installing this library through the Ardu
3939
### Details
4040
- Tested only on Arduino Uno. It would probably not work for the Arduino Due.
4141
- You cannot use the same serial port in your app that is being used by the protocol, e.g. You cannot use `Serial` (Serial0) when the library uses `NeoSerial`, etc. You can modify this lib easily to use other hardware serial ports on bigger boards than the Arduino Uno if you want to free up your USB Serial connection.
42-
- Your app's instance of `ArduinoSerialToTCPBridgeClient` needs to be a pointer and created with `new()`. It doesn't work otherwise and I don't know why yet.
42+
- Your app's instance of `TCPOverSerialClient` needs to be a pointer and created with `new()`. It doesn't work otherwise and I don't know why yet.
4343

4444
- The protocol provides the app an in order, duplicates free and error checked byte stream by adding a CRC32 and simple retry mechanism. See [this](https://en.wikibooks.org/wiki/Serial_Programming/Error_Correction_Methods) for background.
4545
- The **Protocol Gateway** opens a real TCP connection to a set destination on behalf of the **Protocol Client** running on the Arduino, and forwards traffic bi-directionally.
46-
- `ArduinoSerialToTCPBridgeClient` is derived from the standard Arduino `Client` class. This means existing code written for Ethernet/Wi-Fi shields should work with this.
46+
- `TCPOverSerialClient` is derived from the standard Arduino `Client` class. This means existing code written for Ethernet/Wi-Fi shields should work with this.
4747
- `NeoHWSerial` is an alternative for `Serial`, used to gain access to the AVR UART interrupts.
4848
- The protocol cannot run over the standard Serial API or something like software serial because it needs hardware level RX interrupts when bytes arrive.

examples/MQTTClient/MQTTClient.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
* Publish character '1' to topic "LedIn" to turn on the Led on the Arduino Uno and '2' to turn it off.
1212
*/
1313

14-
#include <ArduinoSerialToTCPBridgeClient.h>
14+
#include <TCP_over_Serial.h>
1515
#include <PubSubClient.h>
1616

17-
ArduinoSerialToTCPBridgeClient* s; // Protocol Client running over USB Serial
18-
PubSubClient client; // MQTT Client
17+
TCPOverSerialClient* s; // Protocol Client running over USB Serial
18+
PubSubClient client; // MQTT Client
1919

2020
const char* broker = "mqtt.eclipseprojects.io";
2121
const char* ledTopic = "LedIn";
@@ -25,7 +25,7 @@ uint32_t lastPub = 0;
2525

2626
void setup() {
2727
pinMode(13, OUTPUT);
28-
s = new ArduinoSerialToTCPBridgeClient();
28+
s = new TCPOverSerialClient();
2929
client.setClient(*s);
3030

3131
// MQTT Broker running on same PC the Arduino is connected to.

examples/WebClient/WebClient.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
*/
1414

15-
#include <ArduinoSerialToTCPBridgeClient.h>
15+
#include <TCP_over_Serial.h>
1616

1717
// if you don't want to use DNS (and reduce your sketch size)
1818
// use the numeric IP instead of the name for the server:
@@ -22,10 +22,10 @@ char server[] = "www.google.com"; // name address for Google (using DNS)
2222
// Initialize the Protocol client library
2323
// with the IP address and port of the server
2424
// that you want to connect to (port 80 is default for HTTP):
25-
ArduinoSerialToTCPBridgeClient* client;
25+
TCPOverSerialClient* client;
2626

2727
void setup() {
28-
client = new ArduinoSerialToTCPBridgeClient();
28+
client = new TCPOverSerialClient();
2929

3030
// Open serial communications and wait for port to open:
3131
/*Serial.begin(9600);

keywords.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
# Datatypes (KEYWORD1)
77
#######################################
88

9-
ArduinoSerialToTCPBridgeClient KEYWORD1
9+
TCPOverSerialClient KEYWORD1
1010

1111
#######################################
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

15-
ArduinoSerialToTCPBridgeClient KEYWORD2
15+
TCPOverSerialClient KEYWORD2
1616

1717
#######################################
1818
# Constants (LITERAL1)

library.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name=ArduinoSerialToTCPBridgeClient
1+
name=TCP over Serial
22
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. 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.
5+
sentence=TCP over Serial client connection to a server from the Arduino, using the connected host. (No Ethernet/WiFi shields necessary)
6+
paragraph=Quickly communicate with other servers and make network apps using minimal hardware.
77
category=Communication
88
url=https://github.com/RoanBrand/ArduinoSerialToTCPBridgeClient
99
architectures=*
10-
includes=ArduinoSerialToTCPBridgeClient.h
10+
includes=TCP_over_Serial.h
1111
depends=CRC32 (=2.0.0), NeoHWSerial (=1.6.6), PubSubClient (>=2.8.0)

src/ArduinoSerialToTCPBridgeClient.cpp renamed to src/TCP_over_Serial.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "ArduinoSerialToTCPBridgeClient.h"
1+
#include "TCP_over_Serial.h"
22
#include <NeoHWSerial.h>
33
#include <CRC32.h>
44

5-
static ArduinoSerialToTCPBridgeClient* ser0;
5+
static TCPOverSerialClient* ser0;
66

77
void rxISR0(uint8_t c) {
88
ser0->rxCallback(c);
@@ -26,7 +26,7 @@ ISR(TIMER1_COMPA_vect) {
2626
ackTimeout();
2727
}
2828

29-
ArduinoSerialToTCPBridgeClient::ArduinoSerialToTCPBridgeClient() {
29+
TCPOverSerialClient::TCPOverSerialClient() {
3030
reset();
3131
ser0 = this;
3232
NeoSerial.attachInterrupt(rxISR0);
@@ -45,7 +45,7 @@ ArduinoSerialToTCPBridgeClient::ArduinoSerialToTCPBridgeClient() {
4545
INVALID_RESPONSE -4
4646
DOMAIN_NOT_FOUND -5
4747
*/
48-
int ArduinoSerialToTCPBridgeClient::connect(IPAddress ip, uint16_t port) {
48+
int TCPOverSerialClient::connect(IPAddress ip, uint16_t port) {
4949
uint8_t destination[6] = {
5050
(uint8_t) ((uint32_t) ip),
5151
(uint8_t) ((uint32_t) ip >> 8),
@@ -72,7 +72,7 @@ int ArduinoSerialToTCPBridgeClient::connect(IPAddress ip, uint16_t port) {
7272
}
7373

7474
// Maximum host string of 248 bytes.
75-
int ArduinoSerialToTCPBridgeClient::connect(const char *host, uint16_t port) {
75+
int TCPOverSerialClient::connect(const char *host, uint16_t port) {
7676
uint8_t destination[250];
7777
uint8_t len = 0;
7878

@@ -104,11 +104,11 @@ int ArduinoSerialToTCPBridgeClient::connect(const char *host, uint16_t port) {
104104
return 1;
105105
}
106106

107-
size_t ArduinoSerialToTCPBridgeClient::write(uint8_t b) {
107+
size_t TCPOverSerialClient::write(uint8_t b) {
108108
return write(&b, 1);
109109
}
110110

111-
size_t ArduinoSerialToTCPBridgeClient::write(const uint8_t *buf, size_t size) {
111+
size_t TCPOverSerialClient::write(const uint8_t *buf, size_t size) {
112112
size_t written = 0;
113113

114114
while (written < size) {
@@ -142,7 +142,7 @@ size_t ArduinoSerialToTCPBridgeClient::write(const uint8_t *buf, size_t size) {
142142
return size;
143143
}
144144

145-
int ArduinoSerialToTCPBridgeClient::available() {
145+
int TCPOverSerialClient::available() {
146146
if (rxBufisFull)
147147
return 256;
148148

@@ -153,7 +153,7 @@ int ArduinoSerialToTCPBridgeClient::available() {
153153
}
154154
}
155155

156-
int ArduinoSerialToTCPBridgeClient::read() {
156+
int TCPOverSerialClient::read() {
157157
if (available() == 0)
158158
return -1;
159159

@@ -162,7 +162,7 @@ int ArduinoSerialToTCPBridgeClient::read() {
162162
return ch;
163163
}
164164

165-
int ArduinoSerialToTCPBridgeClient::read(uint8_t *buf, size_t size) {
165+
int TCPOverSerialClient::read(uint8_t *buf, size_t size) {
166166
int have = available();
167167
if (have == 0)
168168
return -1;
@@ -177,30 +177,30 @@ int ArduinoSerialToTCPBridgeClient::read(uint8_t *buf, size_t size) {
177177
return toRead;
178178
}
179179

180-
int ArduinoSerialToTCPBridgeClient::peek() {
180+
int TCPOverSerialClient::peek() {
181181
return rxBuf[rxBufpH];
182182
}
183183

184-
void ArduinoSerialToTCPBridgeClient::flush() {
184+
void TCPOverSerialClient::flush() {
185185
NeoSerial.flush();
186186
}
187187

188-
void ArduinoSerialToTCPBridgeClient::stop() {
188+
void TCPOverSerialClient::stop() {
189189
writePacket(PROTOCOL_DISCONNECT, NULL, 0);
190190
flush();
191191
reset();
192192
//NeoSerial.end();
193193
}
194194

195-
uint8_t ArduinoSerialToTCPBridgeClient::connected() {
195+
uint8_t TCPOverSerialClient::connected() {
196196
return (state == STATE_CONNECTED) ? 1 : 0;
197197
}
198198

199-
ArduinoSerialToTCPBridgeClient::operator bool() {
199+
TCPOverSerialClient::operator bool() {
200200
return 1;
201201
}
202202

203-
void ArduinoSerialToTCPBridgeClient::reset() {
203+
void TCPOverSerialClient::reset() {
204204
stopAckTimer();
205205
state = STATE_DISCONNECTED;
206206
ackOutstanding = false;
@@ -212,7 +212,7 @@ void ArduinoSerialToTCPBridgeClient::reset() {
212212
rxBufisFull = false;
213213
}
214214

215-
boolean ArduinoSerialToTCPBridgeClient::writePacket(uint8_t command, uint8_t* payload, uint8_t pLength) {
215+
boolean TCPOverSerialClient::writePacket(uint8_t command, uint8_t* payload, uint8_t pLength) {
216216
if (pLength > 250)
217217
return false;
218218

@@ -255,7 +255,7 @@ boolean ArduinoSerialToTCPBridgeClient::writePacket(uint8_t command, uint8_t* pa
255255
return true;
256256
}
257257

258-
void ArduinoSerialToTCPBridgeClient::rxCallback(uint8_t c) {
258+
void TCPOverSerialClient::rxCallback(uint8_t c) {
259259
static uint16_t byteCount = 0;
260260
static uint8_t rxState = RX_PACKET_IDLE;
261261

@@ -346,7 +346,7 @@ void ArduinoSerialToTCPBridgeClient::rxCallback(uint8_t c) {
346346
}
347347

348348
// http://www.engblaze.com/microcontroller-tutorial-avr-and-arduino-timer-interrupts/
349-
void ArduinoSerialToTCPBridgeClient::setupAckTimer() {
349+
void TCPOverSerialClient::setupAckTimer() {
350350
cli();
351351
TCCR1A = 0;
352352
TCCR1B = 0;
@@ -356,11 +356,11 @@ void ArduinoSerialToTCPBridgeClient::setupAckTimer() {
356356
sei();
357357
}
358358

359-
void ArduinoSerialToTCPBridgeClient::startAckTimer() {
359+
void TCPOverSerialClient::startAckTimer() {
360360
TCCR1B |= (1 << CS12); // 256 prescaler
361361
}
362362

363-
void ArduinoSerialToTCPBridgeClient::stopAckTimer() {
363+
void TCPOverSerialClient::stopAckTimer() {
364364
TCCR1B &= 0xF8; // remove clk source
365365
TCNT1 = 0; // reset counter
366366
}

src/ArduinoSerialToTCPBridgeClient.h renamed to src/TCP_over_Serial.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef arduinoserialtotcpbridgeclient_H
2-
#define arduinoserialtotcpbridgeclient_H
1+
#ifndef tcpoverserial_H
2+
#define tcpoverserial_H
33

44
#include "Arduino.h"
55
#include "Client.h"
@@ -21,9 +21,9 @@
2121
#define RX_PACKET_GOTCOMMAND 2
2222
#define RX_PACKET_GOTPAYLOAD 3
2323

24-
class ArduinoSerialToTCPBridgeClient : public Client {
24+
class TCPOverSerialClient : public Client {
2525
public:
26-
ArduinoSerialToTCPBridgeClient();
26+
TCPOverSerialClient();
2727

2828
virtual int connect(IPAddress ip, uint16_t port);
2929
virtual int connect(const char *host, uint16_t port);

0 commit comments

Comments
 (0)