Skip to content

Commit

Permalink
Make tcp API now work. Sample usage and caveats below:
Browse files Browse the repository at this point in the history
Sample usage:

First configure device to use @mc-hamster's new wifi stuff:
meshtastic --set wifi_ssid mylanname --set wifi_password mylanpassword

Then reboot the device (so wifi starts up).

(assuming device was assigned addr 192.168.81.45)
meshtastic --info --host 192.168.81.45
(See the usual device info you previously had to get over USB)

Caveats:

* Currently we are limiting to one active TCP connection open at once, if
you open a new session the old one is closed automatically
* There are no access controls/authentication needed to open a TCP
connection to the device
* Currently main.cpp is kinda dumb about how we should schedule work and
we rely on too many helper loop() functions.  Very soon in my queue
(related to all the other cleanup) is to add a basic notion of coroutines,
so that we can get away from freertos threads and this old school arduino
loop function.  Once that cleanup happens we can the a) have much lower
battery consumption (always) and b) super fast response for all operations.
  • Loading branch information
geeksville committed Sep 25, 2020
1 parent d1c3078 commit 2996c7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/esp32/WiFiServerAPI.cpp
Expand Up @@ -52,6 +52,14 @@ void WiFiServerPort::loop()
{
auto client = available();
if (client) {
new WiFiServerAPI(client);
// Close any previous connection (see FIXME in header file)
if (openAPI)
delete openAPI;

openAPI = new WiFiServerAPI(client);
}

if (openAPI)
// Allow idle processing so the API can read from its incoming stream
openAPI->loop();
}
7 changes: 7 additions & 0 deletions src/esp32/WiFiServerAPI.h
Expand Up @@ -29,6 +29,13 @@ class WiFiServerAPI : public StreamAPI
*/
class WiFiServerPort : public WiFiServer
{
/** The currently open port
*
* FIXME: We currently only allow one open TCP connection at a time, because we depend on the loop() call in this class to
* delegate to the worker. Once coroutines are implemented we can relax this restriction.
*/
WiFiServerAPI *openAPI = NULL;

public:
WiFiServerPort();

Expand Down

0 comments on commit 2996c7c

Please sign in to comment.