Skip to content

Commit 700e0fd

Browse files
committed
Do not depend on pin interrupt, instead check for lora packet at every loop start
1 parent a640fed commit 700e0fd

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/EspIdiot.ino

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ void setup(void)
301301
}
302302

303303
if (has_radio) {
304-
LoRa.setPins(15, 9, 2); // not sure about nreset 9
305-
if (!LoRa.begin(915E6)) { // not sure about the frequency, saw in https://github.com/sandeepmistry/arduino-LoRa/blob/master/examples/LoRaSender/LoRaSender.ino
304+
LoRa.setPins(15, 2, 16);
305+
if (!LoRa.begin(915E6)) { // 433E6, 866E6 or 915E6
306306
Serial.println("! starting LoRa failed - assuming no radio attached");
307307
has_radio = false;
308308
}
@@ -383,6 +383,8 @@ void loop(void)
383383
idiotWifiServer.handleClient();
384384
led.loop();
385385

386+
onLoraReceive(LoRa.parsePacket());
387+
386388
if (mqttClient.connected()) {
387389
mqttClient.loop();
388390
}
@@ -412,6 +414,8 @@ void loop(void)
412414

413415
sleep_seconds = 0;
414416

417+
local_address = lora_gateway ? GATEWAY_ADDR: SLAVE_ADDR;
418+
415419
if (!PersistentStore.wifiCredentialsStored()) {
416420
toState(serve_locally);
417421
serveLocallySeconds = 60;
@@ -592,12 +596,10 @@ void loop(void)
592596
}
593597
}
594598
else if (state == setup_lora) {
595-
local_address = lora_gateway ? GATEWAY_ADDR: SLAVE_ADDR;
596-
597599
Serial.printf("? lora mode: %s, address: %d\n", (lora_gateway ? "gateway" : "slave"), local_address);
598600

599601
// documentation: https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md
600-
LoRa.enableCrc();
602+
// LoRa.enableCrc();
601603
// LoRa.setFrequency(866E6); // set in LoRa.begin()
602604
// LoRa.setTxPower(17);
603605
// LoRa.setSpreadingFactor(7);
@@ -607,18 +609,12 @@ void loop(void)
607609
// LoRa.setSyncWord(0x34);
608610

609611
if (lora_gateway) {
610-
toState(listen_lora);
612+
toState(publish);
611613
}
612614
else {
613615
toState(send_lora);
614616
}
615617
}
616-
else if (state == listen_lora) {
617-
Serial.println("? continous receive mode");
618-
LoRa.onReceive(onLoraReceive);
619-
LoRa.receive(); // continuous receive mode
620-
toState(publish);
621-
}
622618
else if (state == send_lora) {
623619
char message[100] = "hello gw!";
624620

src/State.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
STATE(load_config) \
1212
STATE(update_config) \
1313
STATE(setup_lora) \
14-
STATE(listen_lora) \
1514
STATE(send_lora) \
1615
STATE(read_senses) \
1716
STATE(publish) \

0 commit comments

Comments
 (0)