forked from github/esp8266-geigercounter
Add startup delays to handle unstable psus
This commit is contained in:
parent
97527492ef
commit
4e1dbdd2b0
1 changed files with 35 additions and 12 deletions
|
@ -33,16 +33,21 @@ float lastuSv = 0, currentuSv = 0;
|
||||||
char hostname[16];
|
char hostname[16];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
delay(3000);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
delay(2000);
|
||||||
Serial.println("\n");
|
Serial.println("\n");
|
||||||
Serial.println("Hello from esp8266-geigercounter");
|
Serial.println("Hello from esp8266-geigercounter");
|
||||||
|
Serial.printf("Core Version: %s\n", ESP.getCoreVersion().c_str());
|
||||||
|
Serial.printf("Boot Version: %u\n", ESP.getBootVersion());
|
||||||
|
Serial.printf("Boot Mode: %u\n", ESP.getBootMode());
|
||||||
|
Serial.printf("CPU Frequency: %u MHz\n", ESP.getCpuFreqMHz());
|
||||||
|
Serial.printf("Reset reason: %s\n", ESP.getResetReason().c_str());
|
||||||
|
delay(3000);
|
||||||
|
|
||||||
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
||||||
|
|
||||||
// Power up wait
|
|
||||||
delay(2000);
|
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
|
||||||
int32_t chipid = ESP.getChipId();
|
int32_t chipid = ESP.getChipId();
|
||||||
|
|
||||||
Serial.print("MQTT_MAX_PACKET_SIZE: ");
|
Serial.print("MQTT_MAX_PACKET_SIZE: ");
|
||||||
|
@ -61,11 +66,28 @@ void setup() {
|
||||||
snprintf(MQTT_TOPIC_USV_MEASUREMENT, 127, "%s/%s/%s_%s/state", FIRMWARE_PREFIX, hostname, hostname, "uSv");
|
snprintf(MQTT_TOPIC_USV_MEASUREMENT, 127, "%s/%s/%s_%s/state", FIRMWARE_PREFIX, hostname, hostname, "uSv");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONF_WIFI_PASSWORD
|
Serial.print("Connecting to WiFi");
|
||||||
wifiManager.autoConnect(hostname, CONF_WIFI_PASSWORD);
|
|
||||||
#else
|
WiFi.mode(WIFI_STA);
|
||||||
wifiManager.autoConnect(hostname);
|
unsigned long wifiConnectStart = millis();
|
||||||
#endif
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
if (WiFi.status() == WL_CONNECT_FAILED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (millis() - wifiConnectStart > 10000) {
|
||||||
|
WiFiManager wifiManager;
|
||||||
|
#ifdef CONF_WIFI_PASSWORD
|
||||||
|
wifiManager.autoConnect(hostname, CONF_WIFI_PASSWORD);
|
||||||
|
#else
|
||||||
|
wifiManager.autoConnect(hostname);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("\nIP: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
WiFi.hostname(hostname);
|
WiFi.hostname(hostname);
|
||||||
mqttClient.setClient(wifiClient);
|
mqttClient.setClient(wifiClient);
|
||||||
|
@ -220,6 +242,7 @@ void loop() {
|
||||||
timer.run();
|
timer.run();
|
||||||
mqttConnect();
|
mqttConnect();
|
||||||
mqttClient.loop();
|
mqttClient.loop();
|
||||||
|
ESP.wdtFeed();
|
||||||
|
|
||||||
if (geigerCounterSerial.available()) {
|
if (geigerCounterSerial.available()) {
|
||||||
char in = (char) geigerCounterSerial.read();
|
char in = (char) geigerCounterSerial.read();
|
||||||
|
@ -285,7 +308,7 @@ void parseReceivedLine(char* input) {
|
||||||
case IDX_uSv_KEY: if (strcmp(token, "uSv/hr") != 0) return; break;
|
case IDX_uSv_KEY: if (strcmp(token, "uSv/hr") != 0) return; break;
|
||||||
|
|
||||||
case IDX_CPM:
|
case IDX_CPM:
|
||||||
Serial.printf("Current CPM: %s\n", token);
|
Serial.printf("\nCurrent CPM: %s\n", token);
|
||||||
cpm = String(token).toInt();
|
cpm = String(token).toInt();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue