use random device id

This commit is contained in:
technyon
2022-04-02 18:02:49 +02:00
parent 9792110461
commit a6d59af73b
3 changed files with 26 additions and 8 deletions

View File

@@ -19,9 +19,6 @@ void Network::initialize()
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it.
// put your setup code here, to run once:
Serial.begin(115200);
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;

View File

@@ -1,5 +1,6 @@
#pragma once
#define preference_deviceId "deviceId"
#define preference_mqtt_broker "mqttbroker"
#define preference_mqtt_broker_port "mqttport"
#define preference_query_interval_lockstate "lockStInterval"

View File

@@ -3,6 +3,7 @@
#include "Network.h"
#include "WebCfgServer.h"
#include <FreeRTOS.h>
#include "PreferencesKeys.h"
#define ESP32
@@ -34,21 +35,40 @@ void setupTasks()
xTaskCreate(nukiTask, "nuki", 16384, NULL, 1, NULL);
}
uint32_t getRandomId()
{
uint8_t rnd[4];
for(int i=0; i<4; i++)
{
rnd[i] = random(255);
}
uint32_t deviceId;
memcpy(&deviceId, &rnd, sizeof(deviceId));
return deviceId;
}
void setup()
{
Serial.begin(115200);
preferences = new Preferences();
preferences->begin("nukihub", false);
network = new Network(preferences);
nuki = new NukiWrapper("ESP", 2020001, network, preferences);
webCfgServer = new WebCfgServer(nuki, network, preferences);
network->initialize();
uint32_t deviceId = preferences->getUInt(preference_deviceId);
if(deviceId == 0)
{
deviceId = getRandomId();
preferences->putUInt(preference_deviceId, deviceId);
}
nuki = new NukiWrapper("ESP", deviceId, network, preferences);
webCfgServer = new WebCfgServer(nuki, network, preferences);
webCfgServer->initialize();
nuki->initialize();
setupTasks();
// Serial.println(byte_array_dec[0]);
}
void loop()