Merge commit '5dc2e7b0ca1354b54f50e6db6db99acad67003ac'

This commit is contained in:
Pascal Serrarens 2025-02-01 20:15:25 +01:00
commit 8d85881047
4 changed files with 51 additions and 6 deletions

View File

@ -109,4 +109,48 @@ bool StartWifi(const char *wifiSsid, const char *wifiPassword,
return (!hotSpotEnabled);
}
void CheckFirmware(String url, String FIRMWARE_NAME, int FIRMWARE_VERSION) {
Serial.println("Checking for firmware updates.");
WiFiClient client;
HTTPClient httpClient;
String versionURL = url + FIRMWARE_NAME + ".version";
httpClient.begin(client, versionURL);
int httpCode = httpClient.GET();
if (httpCode == 200) {
String newFWVersion = httpClient.getString();
Serial.print("Current firmware version: ");
Serial.println(FIRMWARE_VERSION);
Serial.print("Available firmware version: ");
Serial.println(newFWVersion);
int newVersion = newFWVersion.toInt();
if (newVersion > FIRMWARE_VERSION) {
Serial.println("Preparing to update firmware.");
String firmwareURL = url + FIRMWARE_NAME + ".bin";
t_httpUpdate_return ret = ESPhttpUpdate.update(client, firmwareURL);
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s",
ESPhttpUpdate.getLastError(),
ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
break;
}
} else {
Serial.println("No Firmware update necessary.");
}
} else {
Serial.print("Http Error: ");
Serial.println(httpCode);
}
}
#endif

View File

@ -30,8 +30,8 @@ Participant::Participant(int port) {
this->participants.push_back(this);
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
this->localPort = randomPort;
// int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
this->localPort = port;
// SetupUDP(randomPort, ipAddress, port);
}
@ -41,8 +41,8 @@ Participant::Participant(const char *ipAddress, int port) {
this->participants.push_back(this);
int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
this->localPort = randomPort;
// int randomPort = (rand() % (65535 - 49152 + 1)) + 49152;
this->localPort = port; // randomPort;
// SetupUDP(randomPort, ipAddress, port);
}
@ -90,6 +90,7 @@ void Participant::Update(unsigned long currentTimeMs) {
this->ReceiveUDP();
this->UpdateAll(currentTimeMs);
this->UpdateAll(currentTimeMs);
}
void Participant::ReceiveUDP() {

View File

@ -73,7 +73,7 @@ protected:
public:
/// @brief The type of Thing
unsigned char type = 0;
char *name = nullptr;
const char *name = nullptr;
const char *modelUrl = nullptr;
float modelScale = 1;
// protected Sensor sensor;

View File

@ -17,7 +17,7 @@ void UdpArduino::Setup(int localPort, const char *remoteIpAddress,
std::cout << "No network available!\n";
return;
}
udp.begin(this->remotePort);
udp.begin(this->localPort);
std::cout << "Wifi sync started to port " << this->remotePort << "\n";
#endif