Skip to content

Commit

Permalink
Merge pull request #7 from meshtastic/dev-wifi
Browse files Browse the repository at this point in the history
Bringing in the API changes
  • Loading branch information
mc-hamster authored Sep 20, 2020
2 parents 3412ecf + 5cbe06c commit 468ad39
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion proto
Submodule proto updated from ce422b to 4e431c
2 changes: 1 addition & 1 deletion src/esp32/WiFiServerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ WiFiServerPort::WiFiServerPort() : WiFiServer(MESHTASTIC_PORTNUM) {}

void WiFiServerPort::init()
{
DEBUG_MSG("Listening on TCP port %d\n", MESHTASTIC_PORTNUM);
DEBUG_MSG("API server sistening on TCP port %d\n", MESHTASTIC_PORTNUM);
begin();
}

Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
#include "SPILock.h"
#include "graphics/Screen.h"
#include "main.h"
#include "meshwifi/meshhttp.h"
#include "meshwifi/meshwifi.h"
#include "sleep.h"
#include "timing.h"
#include <OneButton.h>
#include <Wire.h>
#include "meshwifi/meshwifi.h"
#include "meshwifi/meshhttp.h"
// #include <driver/rtc_io.h>

#ifndef NO_ESP32
Expand Down Expand Up @@ -395,6 +395,8 @@ void loop()
userButtonAlt.tick();
#endif

loopWifi();

// Show boot screen for first 3 seconds, then switch to normal operation.
static bool showingBootScreen = true;
if (showingBootScreen && (timing::millis() > 3000)) {
Expand Down
21 changes: 21 additions & 0 deletions src/meshwifi/meshwifi.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "meshwifi.h"
#include "NodeDB.h"
#include "WiFiServerAPI.h"
#include "configuration.h"
#include "main.h"
#include "meshwifi/meshhttp.h"
Expand All @@ -9,6 +10,7 @@
static void WiFiEvent(WiFiEvent_t event);

DNSServer dnsServer;
static WiFiServerPort *apiPort;

bool isWifiAvailable()
{
Expand Down Expand Up @@ -96,6 +98,23 @@ void initWifi()
DEBUG_MSG("Not using WIFI\n");
}

/// Perform idle loop processing required by the wifi layer
void loopWifi()
{
// FIXME, once we have coroutines - just use a coroutine instead of this nasty loopWifi()
if (apiPort)
apiPort->loop();
}

static void initApiServer()
{
// Start API server on port 4403
if (!apiPort) {
apiPort = new WiFiServerPort();
apiPort->init();
}
}

static void WiFiEvent(WiFiEvent_t event)
{
DEBUG_MSG("************ [WiFi-event] event: %d ************\n", event);
Expand Down Expand Up @@ -131,6 +150,7 @@ static void WiFiEvent(WiFiEvent_t event)

// Start web server
initWebServer();
initApiServer();

break;
case SYSTEM_EVENT_STA_LOST_IP:
Expand All @@ -154,6 +174,7 @@ static void WiFiEvent(WiFiEvent_t event)

// Start web server
initWebServer();
initApiServer();

break;
case SYSTEM_EVENT_AP_STOP:
Expand Down
4 changes: 4 additions & 0 deletions src/meshwifi/meshwifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

void initWifi();
void deinitWifi();

/// Perform idle loop processing required by the wifi layer
void loopWifi();

bool isWifiAvailable();

void handleDNSResponse();
Expand Down
5 changes: 4 additions & 1 deletion src/nrf52/wifi-nrf52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ bool isWifiAvailable()
return false;
}

void handleWebResponse() {}
void handleWebResponse() {}

/// Perform idle loop processing required by the wifi layer
void loopWifi() {}

0 comments on commit 468ad39

Please sign in to comment.