Giter Club home page Giter Club logo

serialtowifi's Introduction

SerialToWifi : OTA debugging made easy

This library is a drop-in replacement for the Serial Arduino library that manages I/Os through a remote console over wifi.
Simply include the SerialToWifi.h, configure your host address and port and all the calls to the Serial library will be redirected to your host via wifi. Commands like Serial.println() and Serial.readStringUntil() are all supported.
The connection is initiated by your Arduino/ESP board to your host computer. This means that as long as your host's TCP port is reachable, the device will send its data over standard Serial commands, wherever the board is on your local network or the Internet.
To revert to the original Serial behavior, simply comment out the header file.
To restart debug outputs to the TCP console after a connection loss , a reset of the device is required. See the RECONNECT option to change this behavior.
Please read the "Options" section for potential impact of the library on performance.

Installation

  1. In the Arduino IDE, navigate to Sketch -> Include Library -> Manage Libraries
  2. The Library Manager will open.
  3. Then search for SerialToWifi using the search bar.
  4. Select the latest version and install it.

Example code is available in Sketch -> Examples -> SerialToWifi

TCP Console

You need to install a TCP listener as a display console to manage the input/output from the library. We recommend using NCat from the nmap project. Any other similar TCP listener should work fine. If you are running Windows, a precompiled standalone version is available here: https://github.com/cyberisltd/NcatPortable For other platforms, it can be downloaded from the nmap open source project and is available in the package binaries: https://nmap.org/download.html

Use this command line to have ncat listen on port 6767 on your host machine

ncat -k -l -p 6767 

Library usage

Add the following to your code.

#include <SerialToWifi> // Comment this line to go back to the original Serial library behavior

#ifdef SERIALTOWIFI
    #define SERVER  "YOUR_HOST_IP"
    #define SERVER_PORT 6767
    SerialToWifi serialToWifi(SERVER, SERVER_PORT, TIMESTAMP); // use TIMESTAMP | RECONNECT for both options
    // TIMESTAMP: Displays a timestamp at the beginning of each line
    // RECONNECT: Will try to reconnect if the host becomes unreachable at some point and gets back online. Default behaviour is to stop output after a connection loss.
#endif

void startWifi()
{
  // launch WiFi
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID, PASSWORD);
  if (WiFi.waitForConnectResult() != WL_CONNECTED)
  {
    //Connection Failed! Stop ...
    while (1)
      delay(1000);
  }
}

void setup()
{
    startWifi();
    Serial.begin(115200);
    Serial.println("Starting");
}

Options

Options for the SerialToWifi object are:
TIMESTAMP : Displays a timestamp at the beginning of each line similar to the one in the Arduino console. This option is disabled by default.
RECONNECT : By default, the library does not attempt to reconnect to the console after a failed attempt or connection loss and a reset of the device is required to resume output. The RECONNECT option will attempt reconnection on each call but can add significant delays to your program's execution.

serialtowifi's People

Contributors

invzblio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.