Commit 401460af authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Serial test removed - add delay between halfduplex exchange

parent 425ad89a
......@@ -40,7 +40,7 @@ String signalLevel = "";
#define LED_PIN 13
int brightness = 0;
unsigned long previousMillisLed = 0;
const long intervalLed = 60000 * 3;
const long intervalLed = 60000 * 10;
// Arduino like analogWrite
// value has to be between 0 and valueMax
......@@ -53,9 +53,6 @@ void ledcAnalogWrite(uint8_t channel, uint32_t value, uint32_t valueMax = 255) {
}
void setup() {
Serial.begin(115200); // initialize serial
while (!Serial);
Serial.println("Begin");
// Setup timer and attach timer to a led pin
ledcSetup(LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
......@@ -76,6 +73,7 @@ void setup() {
LoRa.enableCrc();
LoRa.setTxPower(20,14);
LoRa.setSignalBandwidth(7.8E3);
LoRa.setSpreadingFactor(12);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(BAND)) {
drawTextOLED("Starting LoRa failed!");
......@@ -97,7 +95,7 @@ void setup() {
unsigned long previousMillis = 0;
const long interval = 2500;
bool isLoRaOnReceiveMode = false;
bool isLoRaOnSenderMode = false;
bool isLedBegin = true;
bool isLedOn = false;
......@@ -110,7 +108,7 @@ const long intervalLedOff = 18;
//delay before switch off
bool isLedOff = false;
unsigned long previousMillisIsOnLedOff = 0;
const long intervalIsOnLedOff = 30000 * 1;
const long intervalIsOnLedOff = 60000 * 1;
void loop() {
// do nothing
......@@ -121,14 +119,15 @@ void loop() {
digitalWrite(RELE_2, LOW);
}
if(isLoRaOnReceiveMode)
if(isLoRaOnSenderMode)
{
delay(2000);
LoRa.beginPacket();
LoRa.print(lastCommand);
LoRa.endPacket();
LoRa.receive();
isLoRaOnReceiveMode = false;
isLoRaOnSenderMode = false;
}
// ------------ LED -----------------
......@@ -198,8 +197,6 @@ void onReceive(int packetSize)
lastCommand = str;
Serial.println(lastCommand);
if(str.indexOf("p : ") == 0)
{
if(str.indexOf(r1) > 0)
......@@ -211,7 +208,7 @@ void onReceive(int packetSize)
setRele2();
}
isLoRaOnReceiveMode = true;
isLoRaOnSenderMode = true;
}
String val = "";
......@@ -227,7 +224,7 @@ void onReceive(int packetSize)
val = readRele2();
}
isLoRaOnReceiveMode = true;
isLoRaOnSenderMode = true;
lastCommand = str + " " + val;
}
......@@ -240,7 +237,7 @@ void onReceive(int packetSize)
previousMillisLed = millis();
isLoRaOnReceiveMode = true;
isLoRaOnSenderMode = true;
}
signalLevel = String(LoRa.packetRssi(), DEC);
......@@ -250,17 +247,17 @@ void setRele1()
{
digitalWrite(RELE_1, HIGH);
previousMillis = millis();
// switch on light
brightness = 255;
previousMillisLed = millis();
previousMillisIsOnLedOff = millis() + intervalLed;
isLedOn = false;
}
void setRele2()
{
digitalWrite(RELE_2, HIGH);
previousMillis = millis();
// switch on light
brightness = 255;
previousMillisLed = millis();
previousMillisIsOnLedOff = millis() + intervalLed;
isLedOn = false;
}
String readRele1()
......
......@@ -64,16 +64,13 @@ void setup(void)
LoRa.enableCrc();
LoRa.setTxPower(20,14);
LoRa.setSignalBandwidth(7.8E3);
LoRa.setSpreadingFactor(12);
LoRa.setPins(SS, RST, DI0);
if (!LoRa.begin(BAND)) {
drawTextOLED("Starting LoRa failed!", "", "", "");
while (1);
}
Serial.begin(115200); // initialize serial
while (!Serial);
Serial.println("Begin");
// register the receive callback
LoRa.onReceive(onReceive);
......@@ -208,8 +205,6 @@ void loop(void)
client.print(s);
client.stop();
Serial.println(s);
}
//----------------------------------------------------------------------------------------------
......@@ -239,9 +234,15 @@ void onReceive(int packetSize)
lastReceived = str;
}
lastCommand = str;
if (str.indexOf("p : ") == 0) {
lastCommand = str;
}
if (str.indexOf("b : ") == 0) {
lastCommand = str;
}
Serial.println(lastCommand + " " + lastReceived);
lastCommand = str;
signalLevel = String(LoRa.packetRssi(), DEC);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment