Proof reading code

Hello y'all I need you to review the code for my project as I am kind of new to the programming language and the intracies of the esp32-s3. Let me explain you my project : I need an hc sr 501 pir module to detect movement and to wake my esp32 up and send a message via Lora rylr998 protocol. Here is the code and I own an esp32-s3 devkitc1 ESP32-S3-DevKitC-1 v1.1 - ESP32-S3 - — ESP-IDF Programming Guide v5.2 documentation. If you have any improvement I beg you to help. Thank you very much and have a great christmas

#include <Arduino.h>
#include "esp_sleep.h"
#include "driver/rtc_io.h"

#define LORA_RX_PIN 18
#define LORA_TX_PIN 17

String lora_band = "865000000"; //enter band as per your country
String lora_networkid = "5";    //enter Lora Network ID
String lora_address = "1";      //enter Lora address
String lora_RX_address = "2";   //enter Lora RX address

const int wakeupPin = 21;
void setup() {
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, LORA_RX_PIN, LORA_TX_PIN);
  esp_sleep_wakeup_cause_t reason = esp_sleep_get_wakeup_cause();
  delay(500);
  if (reason == ESP_SLEEP_WAKEUP_EXT0) {
    String message = "AT+SEND,3,17,Mouvementdetecte\r\n";
    Serial.Print(message);
  }
  delay(500);
  pinMode(wakeupPin, INPUT_PULLUP);
  rtc_gpio_hold_en((gpio_num_t)wakeupPin);
  delay(500);
  esp_sleep_enable_ext0_wakeup(
      (gpio_num_t)wakeupPin,
      HIGH
  );
  delay(500);
  esp_deep_sleep_start();
}

void loop() {
  // put your main code here, to run repeatedly:

}

Hi and welcome,

An important piece of information you missed in your original post: does this code work as required or not? That will help us understand if you need help debugging or simply to improve style or efficiency.

I am not sure that esp_sleep_enable_ext0_wakeup() will function with ESP32C3. I think it may only function with older models of ESP32. I know the correct function to use, I will check and get back to you.

1 Like

Case matters...

Serial.print(message);

1 Like

Hi, @croutom

Have you tried to compile it?

Tom.... :smiley: :+1: :coffee: :australia:

if your LoRa module is on Serial2

you probably should use the Serial line to send it out...