diff --git a/ArduinoUtils.cpp b/ArduinoUtils.cpp index 0de1370..ccc85d6 100644 --- a/ArduinoUtils.cpp +++ b/ArduinoUtils.cpp @@ -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 \ No newline at end of file diff --git a/Participant.cpp b/Participant.cpp index 367251e..77e5381 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -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() { diff --git a/Thing.h b/Thing.h index 7f5e6c9..612d17f 100644 --- a/Thing.h +++ b/Thing.h @@ -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; diff --git a/UdpArduino.cpp b/UdpArduino.cpp index 40184af..31d81ff 100644 --- a/UdpArduino.cpp +++ b/UdpArduino.cpp @@ -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