In this guide we show how to setup and use the remote server communication plugin for tcMenu. This plugin allows you to reverse the normal connection direction, and have the API side be a server accepting connections from devices. You simply configure the address and port that the connector should connect with, and ensure there is an API listening at the other side.
For this plugin the direction of connection is reversed, and you similarly need to reverse the API connection, IE the API is listening, and the device is connecting. Here is the situation as a flow:
API is listening <---- connection request -------< Device opens connection
API receives tree <---- bootstrap messages -------< Device sends bootstrap
Updates <---- either side can update ---> Updates
First, ensure your menu structure is saved and then choose Code -> Generate Code from the menu. Once the code generation dialog appears, to the right of the current remote type will be a button named “Change”. Click this button and choose:
The only parameter for serial is the name of the port to be used, if you are using the default USB Serial port it will nearly always be Serial
. Otherwise choose the serial port instance for the hardware that you have.
Ethernet library type
: the underlying library that you’re using to make the connection. This plugin supports many common libraries including Ethernet
, UIP
, WiFi
and Stm32Ethernet
How to interpret the address
: You can define the address as a hard-wired string, a define/flag that you provide, or lastly a variable that you will define in your sketch of type const char*
Address of server
: the address of the server where you are accepting connectionsRemote Port
: the port on which the server is listeningYou must ensure that the network library you have used is fully configured before calling setupMenu()
in your sketch.
Presently, only the Java API supports this mode. Within the Java API the following example shows how to use this mode:
com.thecoderscorner.menu.examples.client.ClientThatAcceptsForRemoteExample