Add MorseTest project

and proceed on the mailbox monitory
This commit is contained in:
Joe Tretter
2022-06-11 17:44:28 -05:00
parent 144b18254b
commit 7b6c3fdb16
2 changed files with 28 additions and 22 deletions

View File

@@ -12,4 +12,6 @@
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
lib_deps = bblanchon/ArduinoJson@^6.19.4
lib_deps =
bblanchon/ArduinoJson@^6.19.4
markfickett/Morse@0.0.0-alpha+sha.b4fb9b5739

View File

@@ -3,11 +3,15 @@
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <morse.h>
#define PIN_STATUS 2
#define ONBOARD_LED 2
#define uS_TO_mS_FACTOR 1000
#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex
RTC_RODATA_ATTR int bootCount=0;
RTC_RODATA_ATTR int lastState=0;
// Wifi network credentials
const char* ssid = "JoNelsDarlings";
@@ -55,14 +59,12 @@ void send_notification(){
if (!client.connect(host,port)) {
Serial.println("connection failed");
//blink the led to indicate the failed connection.....
for (int i=0;i<=5;i++) {
Serial.print("!");
digitalWrite(ONBOARD_LED,HIGH);
delay(1000*i);
digitalWrite(ONBOARD_LED,LOW);
delay(100);
}
// send error message in morse code
LEDMorseSender cqSender(PIN_STATUS);
cqSender.setup();
cqSender.setMessage(String("sos"));
cqSender.sendBlocking();
return;
}
@@ -81,31 +83,33 @@ void setup() {
bootCount++;
Serial.begin(9600);
pinMode(ONBOARD_LED,OUTPUT);
pinMode(13,INPUT);
delay(2000); // just a bit of time to start logging..
Serial.printf("Boot #: %d\n",bootCount);
Serial.printf("Boot #: %d LastState: %d\n",bootCount,lastState);
print_wakeup_reason();
/* if (bootCount % 2 == 0){
digitalWrite(ONBOARD_LED,HIGH);
delay(100);
} else {
digitalWrite(ONBOARD_LED,LOW);
} */
wakeup_reason = esp_sleep_get_wakeup_cause();
if(wakeup_reason==ESP_SLEEP_WAKEUP_EXT0){
if(wakeup_reason==ESP_SLEEP_WAKEUP_EXT0 && lastState==0){
connect_wifi();
send_notification();
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,0); //1 = High, 0 = Low
lastState=1;
} else {
Serial.println("Regular boot, going into deep sleep.");
Serial.println("State is 1, doing nothing going into deep sleep. [Mailbox closed]");
if (digitalRead(13)==LOW){
Serial.println("[Mailbox is closed]");
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low
lastState=0;
} else {
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,0); //1 = High, 0 = Low
Serial.println("[Mailbox is open]");
}
}
//esp_sleep_enable_timer_wakeup(30000*uS_TO_mS_FACTOR);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low
Serial.println("Going to sleep now");
delay(1000);
esp_deep_sleep_start();