Skip to content

Commit

Permalink
Network add net->localIP(), ArduinoJson 7.1.0 to 7.2.0
Browse files Browse the repository at this point in the history
pio.ini
-ArduinoJson 7.1.0 to 7.2.0

SysModNetwork.cpp
- add localIP()

SysModInstances and SysModWeb:
- use net->localIP()
  • Loading branch information
ewoudwijma committed Sep 24, 2024
1 parent 4090098 commit 308cb76
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ build_flags =
${STARBASE_USERMOD_LIVE.build_flags} ;+222.204 bytes 11.7%
lib_deps =
${ESPAsyncWebServer.lib_deps} ;alternatively PsychicHttp
https://github.com/bblanchon/ArduinoJson.git # 7.1.0
https://github.com/bblanchon/ArduinoJson.git # 7.2.0
; https://github.com/Jason2866/ESP32_Show_Info.git
;optional:
${STARBASE_USERMOD_E131.lib_deps}
Expand Down
17 changes: 9 additions & 8 deletions src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../User/UserModE131.h"
#endif
#include "SysModSystem.h"
#include "SysModNetwork.h" //for localIP

struct DMX {
byte universe:3; //3 bits / 8
Expand Down Expand Up @@ -285,7 +286,7 @@ class SysModInstances:public SysModule {
//do not set this initially!!!
if (rowNr != UINT8_MAX) {
//if this instance update directly, otherwise send over network
if (instances[rowNr].ip == WiFi.localIP()) {
if (instances[rowNr].ip == net->localIP()) {
mdl->setValue(var, mdl->getValue(insVar, rowNr).as<unsigned8>()); //this will call sendDataWS (tbd...), do not set for rowNr
} else {
sendMessageUDP(instances[rowNr].ip, Variable(var).id(), mdl->getValue(insVar, rowNr));
Expand Down Expand Up @@ -494,7 +495,7 @@ class SysModInstances:public SysModule {

starMessage.sysData.type = 0; //WLED

if (starMessage.header.ip0 == WiFi.localIP()[0]) { // checksum - no other type of message
if (starMessage.header.ip0 == net->localIP()[0]) { // checksum - no other type of message
updateInstance(starMessage);
found = true;
}
Expand All @@ -505,7 +506,7 @@ class SysModInstances:public SysModule {
byte *udpIn = (byte *)&starMessage;
instanceUDP.read(udpIn, packetSize);

if (starMessage.header.ip0 == WiFi.localIP()[0]) { // checksum - no other type of message
if (starMessage.header.ip0 == net->localIP()[0]) { // checksum - no other type of message
updateInstance(starMessage);
found = true;
}
Expand All @@ -520,7 +521,7 @@ class SysModInstances:public SysModule {
if (error)
ppf("handleNotifications i:%d no json l: %d e:%s\n", instanceUDP.remoteIP()[3], strlen(buffer), error.c_str());
else {
if (instanceUDP.remoteIP()[3] != WiFi.localIP()[3]) { //only others
if (instanceUDP.remoteIP()[3] != net->localIP()[3]) { //only others

InstanceInfo *instance = findInstance(instanceUDP.remoteIP()); //if not exist, created
char group1[32];
Expand Down Expand Up @@ -572,7 +573,7 @@ class SysModInstances:public SysModule {
if(!mdls->isConnected) return;
if (!udp2Connected) return;

IPAddress localIP = WiFi.localIP();
IPAddress localIP = net->localIP();
if (!localIP || localIP == IPAddress(255,255,255,255)) localIP = IPAddress(4,3,2,1);

UDPStarMessage starMessage;
Expand Down Expand Up @@ -619,7 +620,7 @@ class SysModInstances:public SysModule {

//other way around: first set instance variables, then fill starMessage
for (InstanceInfo &instance: instances) {
if (instance.ip == WiFi.localIP()) {
if (instance.ip == net->localIP()) {
instance.jsonData.to<JsonObject>(); //clear

//send dash values
Expand Down Expand Up @@ -718,15 +719,15 @@ class SysModInstances:public SysModule {
strncpy(instance.name, udpStarMessage.header.name, sizeof(instance.name)-1);
instance.version = udpStarMessage.header.version;

if (instance.ip == WiFi.localIP()) {
if (instance.ip == net->localIP()) {
esp_wifi_get_mac((wifi_interface_t)ESP_IF_WIFI_STA, instance.sysData.macAddress);
// ppf("macaddress %02X:%02X:%02X:%02X:%02X:%02X\n", instance.macAddress[0], instance.macAddress[1], instance.macAddress[2], instance.macAddress[3], instance.macAddress[4], instance.macAddress[5]);
}

if (udpStarMessage.sysData.type >= 1) {//StarBase, StarLight and forks only
instance.sysData = udpStarMessage.sysData;

if (instance.ip != WiFi.localIP()) { //send from localIP will be done after updateInstance
if (instance.ip != net->localIP()) { //send from localIP will be done after updateInstance
char group1[32];
char group2[32];
if (groupOfName(instance.name, group1) && groupOfName(mdl->getValue("name"), group2) && strcmp(group1, group2) == 0) {
Expand Down
13 changes: 13 additions & 0 deletions src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ void SysModNetwork::loop10s() {
}
}

IPAddress SysModNetwork::localIP() {
#ifdef STARBASE_ETHERNET
if (ETH.localIP()[0] != 0)
return ETH.localIP();
#endif
if (WiFi.localIP()[0] != 0)
return WiFi.localIP();
if (WiFi.softAPIP()[0] != 0)
return WiFi.softAPIP();

return IPAddress();
}

void SysModNetwork::initWiFiConnection() {

if (wfActive ) //allready success && WiFi.localIP()[0] != 0
Expand Down
3 changes: 3 additions & 0 deletions src/Sys/SysModNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

#pragma once
#include "SysModule.h"

#include <DNSServer.h>
Expand Down Expand Up @@ -39,6 +40,8 @@ class SysModNetwork:public SysModule {
void handleAP();
void stopAP();

IPAddress localIP();

private:
#ifdef STARBASE_ETHERNET
bool ethActive = false; //currently only one call to ETH.begin is possible, wether successful or not: reboot needed for other attempt
Expand Down
7 changes: 4 additions & 3 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "SysModFiles.h"
#include "SysModules.h"
#include "SysModPins.h"
#include "SysModNetwork.h" //for localIP

#include "User/UserModMDNS.h"
// got multiple definition error here ??? see workaround below
Expand Down Expand Up @@ -569,7 +570,7 @@ void SysModWeb::serveUpdate(WebRequest *request, const String& fileName, size_t
char message[64];
const char * name = mdl->getValue("name");

print->fFormat(message, sizeof(message)-1, "Update of %s (...%d) %s", name, WiFi.localIP()[3], success?"Successful":"Failed");
print->fFormat(message, sizeof(message)-1, "Update of %s (...%d) %s", name, net->localIP()[3], success?"Successful":"Failed");

ppf("%s\n", message);
request->send(200, "text/plain", message);
Expand Down Expand Up @@ -637,7 +638,7 @@ void SysModWeb::clientsToJson(JsonArray array, bool nameOnly, const char * filte

bool SysModWeb::captivePortal(WebRequest *request)
{
ppf("captivePortal %d %d\n", WiFi.localIP()[3], request->client()->localIP()[3]);
ppf("captivePortal %d %d\n", net->localIP()[3], request->client()->localIP()[3]);

if (ON_STA_FILTER(request)) return false; //only serve captive in AP mode
String hostH;
Expand Down Expand Up @@ -719,7 +720,7 @@ void SysModWeb::serializeInfo(JsonObject root) {
// docInfo["wifi"]["rssi"] = WiFi.RSSI();// mdl->getValue("rssi"); (ro)

root["mac"] = JsonString(mdns->escapedMac.c_str(), JsonString::Copied);
root["ip"] = JsonString(WiFi.localIP().toString().c_str(), JsonString::Copied);
root["ip"] = JsonString(net->localIP().toString().c_str(), JsonString::Copied);
// print->printJson("serveJson", root);
}

Expand Down

0 comments on commit 308cb76

Please sign in to comment.