#include "Arduino.h"
#include "LoRa_E32.h"
#include <ESP8266WiFi.h>
#define FPM_SLEEP_MAX_TIME 0xFFFFFFF
void callback() {
Serial.println("Callback");
Serial.flush();
}
// ---------- esp8266 pins --------------
//LoRa_E32 e32ttl(D3, D4, D5); // Arduino RX <-- e32 TX, Arduino TX --> e32 RX
LoRa_E32 e32ttl(D3, D4, D5, D7, D6);
// -------------------------------------
void printParameters(struct Configuration configuration);
//The setup function is called once at startup of the sketch
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB
}
delay(100);
e32ttl.begin();
e32ttl.setMode(MODE_2_POWER_SAVING);
// e32ttl.resetModule();
// After set configuration comment set M0 and M1 to low
// and reboot if you directly set HIGH M0 and M1 to program
ResponseStructContainer c;
c = e32ttl.getConfiguration();
Configuration configuration = *(Configuration*) c.data;
printParameters(configuration);
configuration.ADDL = 1; // moded for my testing back to mega server
configuration.ADDH = 0;
configuration.CHAN = 0x04;
configuration.OPTION.fixedTransmission = FT_FIXED_TRANSMISSION;
configuration.OPTION.wirelessWakeupTime = WAKE_UP_250;
configuration.OPTION.fec = FEC_1_ON;
configuration.OPTION.ioDriveMode = IO_D_MODE_PUSH_PULLS_PULL_UPS;
configuration.OPTION.transmissionPower = POWER_20;
configuration.SPED.airDataRate = AIR_DATA_RATE_010_24;
configuration.SPED.uartBaudRate = UART_BPS_9600;
configuration.SPED.uartParity = MODE_00_8N1;
e32ttl.setConfiguration(configuration, WRITE_CFG_PWR_DWN_SAVE);
printParameters(configuration);
// ---------------------------
delay(1000);
Serial.println();
Serial.println("Start sleep!");
delay(500);
//wifi_station_disconnect(); //not needed
// gpio_pin_wakeup_enable(GPIO_ID_PIN(D5), GPIO_PIN_INTR_LOLEVEL); // this line added only causes sketch to stop working
// wifi_set_opmode(NULL_MODE);
// wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
// wifi_fpm_open();
// wifi_fpm_set_wakeup_cb(callback);
// wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME);
// delay(1000);
Serial.println();
Serial.println("Start listening!");
e32ttl.begin();
e32ttl.setMode(MODE_1_WAKE_UP);
}
int i = 0;
// The loop function is called in an endless loop
void loop() {
delay(2500);
i++;
struct Message {
char type[6] = "LOT19";
char message[8] = "Flow_LH";
word flow;
} message;
message.flow = 65519;
Serial.println("sending message to 0,3,4");
ResponseStatus rs = e32ttl.sendFixedMessage(0, 3, 4, &message,
sizeof(Message));
Serial.println(rs.getResponseDescription());
}
unsigned long currentMillis = millis(); // grab current time
// Every 10 seconds, calculate and print litres/hour
// if(currentMillis >= (cloopTime + 1000))
// {
// Serial.println(flow_frequency+2); //debug calculation going negative since changing to 10 seconds added +2 to see what is happening as 0 are confusing
// cloopTime = currentMillis; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
// l_hour = (flow_frequency * 6 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour changed 60 to 6 in formula
// flow_frequency = 0; // Reset Counter
// }
// previousMillis = millis();
// delay(2500);
// i++;
void printParameters(struct Configuration configuration) {
Serial.println("----------------------------------------");
Serial.print(F("HEAD : "));
Serial.print(configuration.HEAD, BIN);
Serial.print(" ");
Serial.print(configuration.HEAD, DEC);
Serial.print(" ");
Serial.println(configuration.HEAD, HEX);
Serial.println(F(" "));
Serial.print(F("AddH : "));
Serial.println(configuration.ADDH, DEC);
Serial.print(F("AddL : "));
Serial.println(configuration.ADDL, DEC);
Serial.print(F("Chan : "));
Serial.print(configuration.CHAN, DEC);
Serial.print(" -> ");
Serial.println(configuration.getChannelDescription());
Serial.println(F(" "));
Serial.print(F("SpeedParityBit : "));
Serial.print(configuration.SPED.uartParity, BIN);
Serial.print(" -> ");
Serial.println(configuration.SPED.getUARTParityDescription());
Serial.print(F("SpeedUARTDatte : "));
Serial.print(configuration.SPED.uartBaudRate, BIN);
Serial.print(" -> ");
Serial.println(configuration.SPED.getUARTBaudRate());
Serial.print(F("SpeedAirDataRate : "));
Serial.print(configuration.SPED.airDataRate, BIN);
Serial.print(" -> ");
Serial.println(configuration.SPED.getAirDataRate());
Serial.print(F("OptionTrans : "));
Serial.print(configuration.OPTION.fixedTransmission, BIN);
Serial.print(" -> ");
Serial.println(configuration.OPTION.getFixedTransmissionDescription());
Serial.print(F("OptionPullup : "));
Serial.print(configuration.OPTION.ioDriveMode, BIN);
Serial.print(" -> ");
Serial.println(configuration.OPTION.getIODroveModeDescription());
Serial.print(F("OptionWakeup : "));
Serial.print(configuration.OPTION.wirelessWakeupTime, BIN);
Serial.print(" -> ");
Serial.println(configuration.OPTION.getWirelessWakeUPTimeDescription());
Serial.print(F("OptionFEC : "));
Serial.print(configuration.OPTION.fec, BIN);
Serial.print(" -> ");
Serial.println(configuration.OPTION.getFECDescription());
Serial.print(F("OptionPower : "));
Serial.print(configuration.OPTION.transmissionPower, BIN);
Serial.print(" -> ");
Serial.println(configuration.OPTION.getTransmissionPowerDescription());
Serial.println("----------------------------------------");
}
WOR wemos server cannot send message after wake
Renzo,
I've used your Wemos D1 WOR example on page 7 as my base for my sketch.
The main change is that after it wakes I intend to send a value taken from a flow meter back to my sever. I'm storing these values in Modbus register's.
If I delete the wifi sleep section my sketch works, if i add in only the GPIO interrupt it no longer works.
For my test setup I'm using a fixed value for my flow reading and therefore have commented out the flow sampling section
I've wired the E32 Lora as your diagram and works with the following connections :LoRa_E32 e32ttl(D3, D4, D5, D7, D6);
My code for the node is below, let me know if something is clearly wrong