markwomack / TeensyNetworkHub

A basic network hub that provides TCP and UPD ports using either WiFi or native ethernet.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TeensyNetworkHub

TeensyNetworkHub implements a basic network hub interface for Teensy microcontrollers which provides access to TCP and UDP. It is implemented with a common set of classes that can be used with either WiFi or native ethernet. The purpose of this library is to make it easy to switch code from using WiFi as the underlying network to using native ethernet, and vica-versa. Switching your sketch code between WiFi and native ethernet versions only requires a few lines of changes, with all of the primary usage remaining the same.

WiFiNINA Library

This version of the network hub implemented to work with the Adafruit AirLift board or comparable ESP32 board. The code requires that the Adafruit fork of the WiFiNINA library be available in your Arduino library path. The latest version of the WiFiNINA library (from Arduino), is not compatible due to the support for different SPI pins added in the Adafruit fork.

Use the WiFiNINANetworkHub class in your code to use this implementation.

QNEthernet Library

This version of the network hub is implemented to work with the QNEthernet library.

Use the QNEthernetNetworkHub class in your code to use this implementation.

Native Ethernet Library

This version of the network hub is implemented to work with the NativeEthernet library that ships as part of the Teensyduino installation.

Use the NativeEthernetNetworkHub class in your code to use this implementation.

NetworkHub

The NetworkHub interface defines the common interface provided for all subclass specific versions (WiFi, QNEthernet, NativeEthernet). It provides methods for creating the primary objects to interact with the underlying network.

Defines the interface for client interface to the network. The getClient method of NetworkHub should be called to create a new instance. Instances are also returned by NetworkServer.available().

Defines the interface for a server interface to the network. The getServer method of NetworkHub should be called to create a new instance.

Defines the interface for a UDP interface to the network. The getUDP method of NetworkHub should be called to create a new instance.

Examples

The included examples come from the original NativeEthernet examples. They demonstrate basic usage for NetworkClient, NetworkServer, and NetworkUDP. The connect_network_hub.h file demonstrates how to connect to each implementation. You probably won't want to use this file in your own code, instead choosing the implemenation you want to use in your project. But if you organize your code to maintain the setup and connection specific code to one file or class, then if you need to switch implemenations, then it is just a simple file change/swap. The rest of your code will remain the same.

Extending

If you have a favorite network library for connecting to the internet, it is easy to extend TeensyNetworkHub to support it. You will need to implement wrappers to integrate the library with TeensyNetworkHub, and implement a version of NetworkHub to iniitalize the connection and provide the clients, servers, and UDPs. Please see WiFiNINANetworkHub, QNEthernetNetworkHub, or EthernetNetworkHub for examples.

Just as an example, I was able to add the implementation for the QNEthernet library in under and hour, with another hour to work out some kinks.

Suggestions, Bugs, Concerns

If you have any suggestions or bugs, please open an issue.

About

A basic network hub that provides TCP and UPD ports using either WiFi or native ethernet.

License:MIT License


Languages

Language:C++ 100.0%