For/while loop & function input

Hi everyone. Thanks in advance for your time.

This is my first post so I'll try to do it according to the forum rules.

Description:

What I am trying to do is have an arduino Pro Mini 328P 3.3V measure the water level of a thing where cattle drinks on a farm and send that data to a Nodemcu v3 connected to wifi and have it post data to google sheets.

For this I've attached a potentiometer that has a lever that moves with water level changes.

Also, as this device is located where no power is available, it will be battery operated. For this reason, I've decided to add a ds3231 RTC to have everything sleep when in no use. Ideally I believe that sleeping for 5 minutes and waking up for a minute or so in order to send data through LoRa should be enough as continuous readings are not necessary nor useful.

The code I've modified is below.

I mainly have two questions:

  1. How do I get the "system" to stay awake for a minute or so while it sends data to the base station? My guess is a for or while loop should be the answer, I just don't manage to get an idea of how to code it. Towards the end of the code in the loop function.

  2. When loRafunction is defined, I don't manage to understand how it gets the proper data to be sent over LoRa. I try to understand this because I would like to have it broadcast the actual data it pot produces when it is between predefined boundaries, and to send a custom message when outside those boundaries.
    This is only to know whether measurements are fine or there is an issue with the remote arduino.

/**
 * Modified from:
 * 
 * Author:Ab Kurk
 * version: 1.0
 * date: 4/02/2018
 * Description: 
 * This sketch is part of the guide to putting your Arduino to sleep
 * tutorial. We use the:
 * Adafruit DS3231 RTC
 * Adafruit 5V ready Micro SD break out board
 * Arduino Pro Mini
 * DHT11 or DHT22 humidety/Temperature sensor
 * In this example we use the RTC to wake up the Arduino to log the temp and humidity on to an SD card.
 * After the data has been logged the Arduino goes back to sleep and gets woken up 5 minutes later to 
 * start all over again
 * Link To Tutorial http://www.thearduinomakerman.info/blog/2018/1/24/guide-to-arduino-sleep-mode
 * Link To Project   http://www.thearduinomakerman.info/blog/2018/2/5/wakeup-rtc-datalogger
 */


//-----------------------------------------------------------------------------------------

// Libraries used:

#include <Arduino.h>
#include <avr/sleep.h>//this AVR library contains the methods that controls the sleep modes
#define interruptPin 3 //Pin we are going to use to wake up the Arduino
#include <DS3232RTC.h>  //RTC Library https://github.com/JChristensen/DS3232RTC
//#include "DHT.h"        // Adafruit DHT Library for the DHT 11 or DHT 22 https://github.com/adafruit/DHT-sensor-library/archive/master.zip
#include <SPI.h>        //SPI library for the sd breakout board. Part of the Arduino IDE
//#include <SD.h>         //SD library for the sd breakout board. Part of the Arduino IDE
#include <LoRa.h>  // LoRa library for the 

//-----------------------------------------------------------------------------------------

//VARIABLE DEFINITIONS 

//RTC Module global variables
const int time_interval=1;// Sets the wakeup intervall in minutes

// 
int const waterLevelpin = A1; // The pin used as input for the water level
//int waterLevel= 0; //initial setup of the water level variable
int timeDelay = 2500; // How long to delay the sending of the packet for
//int waterLevel= analogRead(waterLevelpin); // Creates an int for the measurement of the potentiometer

//-----------------------------------------------------------------------------------------


// Functions definitions

// The function that wakes the arduino up
void wakeUp(){
  Serial.println("Interrrupt Fired");//Print message to serial monitor
   sleep_disable();//Disable sleep mode
  detachInterrupt(1); //Removes the interrupt from pin 2;
 
}

// Function that puts the arduino to sleep 

void Going_To_Sleep(){
    sleep_enable();//Enabling sleep mode
    attachInterrupt(1, wakeUp, LOW);//attaching a interrupt to pin d2
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Setting the sleep mode, in our case full sleep
    digitalWrite(LED_BUILTIN,LOW);//turning LED off
    time_t t;// creates temp time variable
    t=RTC.get(); //gets current time from rtc
    Serial.println("Sleep  Time: "+String(hour(t))+":"+String(minute(t))+":"+String(second(t)));//prints time stamp on serial monitor
    delay(1000); //wait a second to allow the led to be turned off before going to sleep
    sleep_cpu();//activating sleep mode
    Serial.println("just woke up!");//next line of code executed after the interrupt 
    digitalWrite(LED_BUILTIN,HIGH);//turning LED on
    //temp_Humi();//function that reads the temp and the humidity
    t=RTC.get();
    Serial.println("WakeUp Time: "+String(hour(t))+":"+String(minute(t))+":"+String(second(t)));//Prints time stamp 
    //Set New Alarm
    RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t)+time_interval, 0, 0);
  
  // clear the alarm flag
  RTC.alarm(ALARM_1);
  }

//------------------------------LoRa Function----------------------------------------------

void loRafunction(){
    //waterLevel= analogRead(waterLevelpin);
int realWaterlevel= map(analogRead(waterLevelpin),0,210,0,100);
    Serial.print("Water level: ");

  if (realWaterlevel<=150){
    //realWaterlevel=realWaterlevel;
    Serial.println(realWaterlevel);
  }
    else{
    Serial.println("9999");
  }
  
  
  //Serial.println(realWaterlevel);

  // send packet
  LoRa.beginPacket();
  //LoRa.print("Water level ");
  LoRa.print(realWaterlevel);
  LoRa.endPacket();


  delay(timeDelay);
}


//-----------------------------------------------------------------------------------------



void setup() {


  pinMode(LED_BUILTIN,OUTPUT);//We use the led on pin 13 to indecate when Arduino is A sleep
  pinMode(interruptPin,INPUT_PULLUP);//Set pin d2 to input using the buildin pullup resistor
  digitalWrite(LED_BUILTIN,HIGH);//turning LED on

  Serial.begin(9600);//Start Serial Comunication

//------------------------------
// Lora begin 
  while (!Serial);

  Serial.println("LoRa Sender");

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

//------------------------------
  
  // initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags
    RTC.setAlarm(ALM1_MATCH_DATE, 0, 0, 0, 1);
    RTC.setAlarm(ALM2_MATCH_DATE, 0, 0, 0, 1);
    RTC.alarm(ALARM_1);
    RTC.alarm(ALARM_2);
    RTC.alarmInterrupt(ALARM_1, false);
    RTC.alarmInterrupt(ALARM_2, false);
    RTC.squareWave(SQWAVE_NONE);
    /*
     * Uncomment the block block to set the time on your RTC. Remember to comment it again 
     * otherwise you will set the time at everytime you upload the sketch
    */
     /*/ Begin block
     tmElements_t tm;
    tm.Hour = 19;               // set the RTC to an arbitrary time
    tm.Minute = 02;
    tm.Second = 00;
    tm.Day = 7;
    tm.Month = 2;
    tm.Year = 2019 - 1970;      // tmElements_t.Year is the offset from 1970
    RTC.write(tm);              // set the RTC from the tm structure
    // Block end * */
     time_t t; //create a temporary time variable so we can set the time and read the time from the RTC
    t=RTC.get();//Gets the current time of the RTC
    RTC.setAlarm(ALM1_MATCH_MINUTES , 0, minute(t)+time_interval, 0, 0);// Setting alarm 1 to go off 5 minutes from now
    // clear the alarm flag
    RTC.alarm(ALARM_1);
    // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
    RTC.squareWave(SQWAVE_NONE);
    // enable interrupt output for Alarm 1
    RTC.alarmInterrupt(ALARM_1, true);
}

//-----------------------------------------------------------------------------------------


void loop() {
 delay(1000);//wait 5 seconds before going to sleep. In real senairio keep this as small as posible

//How do I get the loRafunction() to loop for say a minute and then get the arduino board to sleep??
//Maybe a for or while loop using the timer of the connected RTC??
loRafunction();


 Going_To_Sleep();
}

Like I said, thanks in advance for your time. I hope I posted everything according to rules.

What I am trying to do is have an arduino Pro Mini 328P 3.3V measure the water level of a thing where cattle drinks on a farm and send that data to a Nodemcu v3 connected to wifi and have it post data to google sheets.

but

  1. When loRafunction is defined, I don't manage to understand how it gets the proper data to be sent over LoRa. I try to understand this because I would like to have it broadcast the actual data it pot produces when it is between predefined boundaries, and to send a custom message when outside those boundaries.
    This is only to know whether measurements are fine or there is an issue with the remote arduino.

The mentioned hardware doesn't include a LoRa transceiver. Maybe that's your main problem.

Uhh. :confused: Sorry for that mistake. All the hardware is included. I’ve tested everything and got to post data to google sheets.

It is a LORA RA-01 module

However when I try to add the rtc/sleep part I don’t know how to get it to work the way I intend.

Thanks for your time!

Post links to all hardware used!
Post a wiring diagram showing all components!

Bigger battery?

Look at the ones that they use in drones. Massive power, cheap and small.

-jim lee

Hi everyone, I've been busy trying to get a better version of what I'm trying to build.

Description: It is a device to measure water level remotely using LoRa technology and post data to Google sheets.

Hardware used:

  1. On the sender side:

Arduino Pro Mini 3.3 328P Clone
RTC DS3231 to wake the board up
Regular POT to measure water level
LoRa Ra-01 module V1.4
Ultrafire HY 18650 7800mAh, 3.7 Li-ion battery solar charged (It is part of one of those solar led lights, which I found easier to use)
To connect to computer and upload sketches also attach a FTDI 232 module

  1. On the receiver side:

Nodemcu V3 LoLin
LoRa Ra-01 module

The Wiring is as follows:

For the Arduino Pro Mini

PRO MINI--POT----RTC----LORA----BATTERY
VCC---------VCC----VCC----VCC-------VCC
GND--------GND----GND----GND-------GND
A1-----------DATA
A4--------------------SCL
A5--------------------SDA
D3--------------------SQW
D10-----------------------------NSS
D11-----------------------------MOSI
D12-----------------------------MISO
D13-----------------------------SCK
D9-------------------------------RST
D2-------------------------------DIO0

(Sorry, can't seem to get to make a table here)

For the Nodemcu V3:

NODEMCU V3------------------LORA MODULE

VCC----------------------------------VCC
GND----------------------------------GND
D8-------------------------------------NSS
D7-------------------------------------MOSI
D6-------------------------------------MISO
D5-------------------------------------SCK
D1-------------------------------------DIO0
D0-------------------------------------RST


Found out that if add "LoRa.end(); in the sender code, the mA used
fall dramatically.


I am attaching the code since the post exceeds 9000 characters.

Issues:

  1. After some time, the system stops working. No data is uploaded to Google Sheets. (Even when the I power things from the USB with my computer).

  2. I am sure I am making some mistakes in regards to coding, so any heads up, suggestions and ideas are welcome in advance.

Receiver.txt (25.2 KB)

Sender.txt (30.3 KB)

RECEIVER

/*
  LoRa Duplex communication
  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.
  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an
  created 28 April 2017
  by Tom Igoe
*/
#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

// Connecting to WiFi
String readString;
const char* ssid = "Red de H"; // Here you put your netowrks name
const char* password = "antitesis2019"; // Here you put your network's password
const char* host = "script.google.com";//script.google.com:443/HTTPS
const int httpsPort = 443;
WiFiClientSecure client;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID = "AKfycbwMIKZ9DrZBlH9L6glOzDfKe-VBAdVWoK2NL6BQQQUhJoxIC80";  // Replace by your GAS service id. This is the part of the address of your google script that doesn¡t change.




const int csPin = 15;          // LoRa radio chip select
const int resetPin = 16;       // LoRa radio reset
const int irqPin = 5;         // change for your board; must be a hardware interrupt pin

String outgoing;              // outgoing message

byte msgCount = 0;            // count of outgoing messages
byte localAddress = 0xBB;     // address of this device
byte destination = 0xFF;      // destination to send to
long lastSendTime = 0;        // last send time
int interval = 2000;          // interval between sends



void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte incomingLength = LoRa.read();    // incoming msg length

  String incoming = "";

  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }

  if (incomingLength != incoming.length()) {   // check length for error
    Serial.println("error: message length does not match length");
    return;                             // skip rest of function
  }

  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    Serial.println("This message is not for me.");
    return;                             // skip rest of function
  }

  // if message is for this device, or broadcast, print details:
  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Sent to: 0x" + String(recipient, HEX));
  Serial.println("Message ID: " + String(incomingMsgId));
  Serial.println("Message length: " + String(incomingLength));
  Serial.println("Message: " + incoming);
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println("Snr: " + String(LoRa.packetSnr()));
  Serial.println();
}

void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(msgCount);                 // add message ID
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}

void sendData(int x, int y)
{
client.setInsecure();
 Serial.print("connecting to ");
 Serial.println(host);
 if (!client.connect(host, httpsPort)) {
   Serial.println("connection failed");
   return;
 }
 if (client.verify(fingerprint, host)) {
 Serial.println("certificate matches");
 } else {
 Serial.println("certificate doesn't match");
 }
 String string_x     =  String(x, DEC);
 String string_y     =  String(y, DEC);
 /*This url string below is where you tell google sheets which data and how to add it to
 the sheet. It is woth taking a look at it.
 https://script.google.com/macros/s/yourcodehere/exec?A=1&temperature=2&humidity=3
 */
 String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_x + "&humidity=" + string_y; 
 Serial.print("requesting URL: ");
 Serial.println(url);
 client.print(String("GET ") + url + " HTTP/1.1\r\n" +
        "Host: " + host + "\r\n" +
        "User-Agent: BuildFailureDetectorESP8266\r\n" +
        "Connection: close\r\n\r\n");
 Serial.println("request sent");
 while (client.connected()) {
 String line = client.readStringUntil('\n');
 if (line == "\r") {
   Serial.println("headers received");
   break;
 }
 }
 String line = client.readStringUntil('\n');
 if (line.startsWith("{\"state\":\"success\"")) {
 Serial.println("esp8266/Arduino CI successfull!");
 } else {
 Serial.println("esp8266/Arduino CI has failed"); // What does this mean?
 }
 Serial.println("reply was:");
 Serial.println("==========");
 Serial.println(line);
 Serial.println("==========");
 Serial.println("closing connection");
 delay(10000);
}

void setup() {
  Serial.begin(9600);                   // initialize serial
  while (!Serial);
delay(10);
  Serial.println();
  Serial.println(".");
  Serial.println(".");
  Serial.println("LoRa Receiver and post to Google Sheets");
  Serial.println("Setting up Lora Receiver");
  Serial.println(".");
  Serial.println(".");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    
    Serial.print(".");
  }       



  Serial.println("LoRa Duplex");

  // override the default CS, reset, and IRQ pins (optional)
  LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

  if (!LoRa.begin(433E6)) {             // initialize ratio at 915 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  Serial.println("LoRa init succeeded.");
}

void loop() {
  // parse for a packet, and call onReceive with the result:
  onReceive(LoRa.parsePacket());


  if (LoRa.parsePacket()>1) {
    String message = "Got your message, go to sleep!";   // send a message
    sendMessage(message);
    Serial.println("Sending " + message);
    lastSendTime = millis();            // timestamp the message
    interval = random(2000) + 1000;    // 2-3 seconds
  delay(1500);
  int c=(char)LoRa.read();
      int a, b;
   a= c;
   b=LoRa.packetRssi(); //Here I could add a new variable, possibly for humidity or temperature
   delay(1500);
   sendData(a,b);
  delay(1500);
  }
}

Updating the code used as it didn't actually post usable data to google sheets.

I still have to test the distance I can reach with the LoRa.

Updates and photos coming soon!

Receiver.txt (23.8 KB)

Sender.txt (33.5 KB)

Hi everyone, I can't seem to get the code to work. I've tried everything I can think of.
The big problem is that I cant get to use the information I get from the sender outside the definition of that function. I mean I don't know how to pass it to the next function sendData() inside the loop function.

/*RECEIVER
    LoRa Duplex communication
    Sends a message every half second, and polls continually
    for new incoming messages. Implements a one-byte addressing scheme,
    with 0xFF as the broadcast address.
    Uses readString() from Stream class to read payload. The Stream class'
    timeout may affect other functuons, like the radio's callback. For an
    created 28 April 2017
    by Tom Igoe
*/
#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>


// Connecting to WiFi
String readString;
const char* ssid  =  "Red de H";   // Here you put your netowrks name
const char* password  =  "antitesis2019";   // Here you put your network's password
const char* host  =  "script.google.com"; //script.google.com:443/HTTPS
const int httpsPort  =  443;
WiFiClientSecure client;
const char* fingerprint  =  "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID  =  "AKfycbwMIKZ9DrZBlH9L6glOzDfKe-VBAdVWoK2NL6BQQQUhJoxIC80";    // Replace by your GAS service id. This is the part of the address of your google script that doesn¡t change.

String incomingg;


const int csPin  =  15;            // LoRa radio chip select
const int resetPin  =  16;         // LoRa radio reset
const int irqPin  =  5;           // change for your board; must be a hardware interrupt pin

String outgoing;                // outgoing message

byte msgCount  =  0;              // count of outgoing messages
byte localAddress  =  0xBB;       // address of this device
byte destination  =  0xFF;        // destination to send to
long lastSendTime  =  0;          // last send time
int interval  =  2000;            // interval between sends



void onReceive(int packetSize)  {
    if  (packetSize  ==  0) return;            // if there's no packet, return

    // read packet header bytes:
    int recipient  =  LoRa.read();            // recipient address
    byte sender  =  LoRa.read();              // sender address
    byte incomingMsgId  =  LoRa.read();       // incoming msg ID
    byte incomingLength  =  LoRa.read();      // incoming msg length

    String incoming  =  "";

    while  (LoRa.available()) {
        incoming  +=  (char)LoRa.read();
      
  }

    if  (incomingLength  !=  incoming.length()) {
       // check length for error
        Serial.println("error: message length does not match length");
        return;                               // skip rest of function
      
  }

    // if the recipient isn't this device or broadcast,
    if  (recipient  !=  localAddress  &&  recipient  !=  0xFF) {
        Serial.println("This message is not for me.");
        return;                               // skip rest of function
      
  }

    // if message is for this device, or broadcast, print details:
    Serial.println("Received from: 0x"  + String(sender,  HEX));
    Serial.println("Sent to: 0x"  + String(recipient,  HEX));
    Serial.println("Message ID: "  + String(incomingMsgId));
    Serial.println("Message length: "  + String(incomingLength));
    Serial.println("Message: "  + incoming);
    Serial.println("RSSI: "  + String(LoRa.packetRssi()));
    Serial.println("Snr: "  + String(LoRa.packetSnr()));
    Serial.println();

}

void sendMessage(String outgoing)  {
    LoRa.beginPacket();                     // start packet
    LoRa.write(destination);                // add destination address
    LoRa.write(localAddress);               // add sender address
    LoRa.write(msgCount);                   // add message ID
    LoRa.write(outgoing.length());          // add payload length
    LoRa.print(outgoing);                   // add payload
    LoRa.endPacket();                       // finish packet and send it
    msgCount++;                             // increment message ID
}

void sendData(int x,  int y)
{
  client.setInsecure();
   Serial.print("connecting to ");
   Serial.println(host);
   if  (!client.connect(host,  httpsPort))  {
       Serial.println("connection failed");
       return;
     
  }
   if  (client.verify(fingerprint,  host))  {
     Serial.println("certificate matches");
     
  } else  {
     Serial.println("certificate doesn't match");
     
  }
   String string_x      =   String(x,  DEC);
   String string_y      =   String(y,  DEC);
   /*This url string below is where you tell google sheets which data and how to add it to
   the sheet. It is woth taking a look at it.
   https://script.google.com/macros/s/yourcodehere/exec?A=1&temperature=2&humidity=3
   */
   String url  =  "/macros/s/"  + GAS_ID  + "/exec?temperature="  + string_x  + "&humidity="  + string_y;  
   Serial.print("requesting URL: ");
   Serial.println(url);
   client.print(String("GET ")  + url  + " HTTP/1.1\r\n"  +
                         "Host: "  + host  + "\r\n"  +
                         "User-Agent: BuildFailureDetectorESP8266\r\n"  +
                         "Connection: close\r\n\r\n");
   Serial.println("request sent");
   while  (client.connected())  {
     String line  =  client.readStringUntil('\n');
     if  (line  ==  "\r") {
         Serial.println("headers received");
         break;
       
    }
     
  }
   String line  =  client.readStringUntil('\n');
   if  (line.startsWith("{\"state\":\"success\""))  {
     Serial.println("esp8266/Arduino CI successfull!");
     
  } else  {
     Serial.println("esp8266/Arduino CI has failed");   // What does this mean?
     
  }
   Serial.println("reply was:");
   Serial.println("==========");
   Serial.println(line);
   Serial.println("==========");
   Serial.println("closing connection");
   delay(10000);
}

void setup()  {
    Serial.begin(9600);                     // initialize serial
    while  (!Serial);
  delay(10);
    Serial.println();
    Serial.println(".");
    Serial.println(".");
    Serial.println("LoRa Receiver and post to Google Sheets");
    Serial.println("Setting up Lora Receiver");
    Serial.println(".");
    Serial.println(".");
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid,  password);
    while  (WiFi.status()  !=  WL_CONNECTED) 
      {
        delay(500);
        
        Serial.print(".");
      
  }       



    Serial.println("LoRa Duplex");

    // override the default CS, reset, and IRQ pins (optional)
    LoRa.setPins(csPin,  resetPin,  irqPin); // set CS, reset, IRQ pin

    if  (!LoRa.begin(433E6)) {
                 // initialize ratio at 915 MHz
        Serial.println("LoRa init failed. Check your connections.");
        while  (true);                         // if failed, do nothing
      
  }

    Serial.println("LoRa init succeeded.");
}

void loop()  {
    // parse for a packet, and call onReceive with the result:
   

  if ((char)LoRa.read() !=0) {
    String message = "Got your message, go to sleep!";   // send a message
    sendMessage(message);
    Serial.println("Sending " + message);
    lastSendTime = millis();            // timestamp the message
    interval = random(2000) + 1000;    // 2-3 seconds
    
  }
  Serial.println(incomingg);
    int a, b;
    a = incomingg.toInt();
    //Serial.println (a);
    b = LoRa.packetRssi(); //Here I could add a new variable, possibly for humidity or temperature
    delay(1500);
    sendData(a, b);
    delay(1500);

  // parse for a packet, and call onReceive with the result:
  onReceive(LoRa.parsePacket());
}

You have a global variable called incomingg and you have a local variable called incoming. Maybe once you have detected a valid message you could copy incoming to incomingg? (The copy operator is written as "=".)

Guys, I need your help. This is driving me crazy.

On the receiving side of the set up, I have the Nodemcu V3. Inside the void loop I am trying to have the code reply only when a new message is received and to "listen" for new messages the rest of the time.

/*RECEIVER
  LoRa Duplex communication
  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.
  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an
  created 28 April 2017
  by Tom Igoe
*/
#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

// Connecting to WiFi
String readString;
const char* ssid = "Red de H"; // Here you put your netowrks name
const char* password = "antitesis2019"; // Here you put your network's password
const char* host = "script.google.com";//script.google.com:443/HTTPS
const int httpsPort = 443;
WiFiClientSecure client;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID = "myGAS";  // Replace by your GAS service id. This is the part of the address of your google script that doesn¡t change.

String inmessage;
String incominglength;


const int csPin = 15;          // LoRa radio chip select
const int resetPin = 16;       // LoRa radio reset
const int irqPin = 5;         // change for your board; must be a hardware interrupt pin

String outgoing;              // outgoing message



byte msgCount = 0;            // count of outgoing messages
byte localAddress = 0xFF;     // address of this device
byte destination = 0xBB;      // destination to send to
long lastSendTime = 0;        // last send time
int interval = 2000;          // interval between sends

void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(msgCount);                 // add message ID
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}

void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte incomingLength = LoRa.read();    // incoming msg length

  String incoming = "";                 // payload of packet

  while (LoRa.available()) {            // can't use readString() in callback, so
    incoming += (char)LoRa.read();      // add bytes one by one
  }

  if (incomingLength != incoming.length()) {   // check length for error
    Serial.println("error: message length does not match length");
    return;                             // skip rest of function
  }

  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    Serial.println("This message is not for me.");
    return;                             // skip rest of function
  }

  // if message is for this device, or broadcast, print details:
  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Sent to: 0x" + String(recipient, HEX));
  Serial.println("Message ID: " + String(incomingMsgId));
  Serial.println("Message length: " + String(incomingLength));
  Serial.println("Message: " + incoming);
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println("Snr: " + String(LoRa.packetSnr()));
  Serial.println();
  inmessage=incoming;
}


void setup() {
  Serial.begin(9600);                   // initialize serial
  while (!Serial);

  Serial.println("LoRa Duplex with callback");

  // override the default CS, reset, and IRQ pins (optional)
  LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

  if (!LoRa.begin(433E6)) {             // initialize ratio at 915 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while (true);                       // if failed, do nothing
  }

  LoRa.onReceive(onReceive);
  LoRa.receive();
  Serial.println("LoRa init succeeded.");
}


void loop() {
LoRa.receive(); 
delay(1000);

if(inmessage.toInt()>=0){
  for(int i=0;i<10;i++) {
    String message = "HeLoRa World!";   // send a message
    sendMessage(message);
    Serial.println("Sending " + message);
    lastSendTime = millis();            // timestamp the message
    interval = random(2000) + 1000;     // 2-3 seconds
                delay(100);        // go back into receive mode
  }
}
}

Any help on how to manage this would be ver much appreciated!

Don't use delay(1000).

Use autoformat to correctly indent your code.

What does it actually do? Does it print anything to Serial?

Ok guys, I think I pretty much got it working almost the way I intended it to.

However, there are a few issues I would like to ask you guys about:

  1. The code stops posting to google after a random amount of time usually posts at least 5 or 6 times before it stops doing so.

  2. About the current supply to the Rx side with the Nodemcu v3 and the LoRa 01. Anyone knows how much current should be supplied to the LoRa module?
    From what I've read, the Nodemcu can only supply around 16ma per pin, and I'm not sure that's enough or not for it to work properly and if it would be optimal for reception in a long distance setting.

So, if anyone has any ideas, they are much appreciated.

Sender.txt (11.1 KB)

Receiver.txt (7.89 KB)

Don't change your .ino files to .txt.

If the files are not excessively long, post them inline with [ code ] tags. You will get more eyes looking at your code that way.

Hi. Thanks. I tried to do so but the code seems to be quite long for it to be posted between tags. And when trying to upload the files they wouldn’t load because they are in an unsupported format (I don’t remember which now, because I’m using platform io, not the Arduino ide).

I’ll try to shorten as much the code.

Thanks!

Here is the sender side

/*SENDER
    LoRa Duplex communication
    Sends a message every half second, and polls continually
    for new incoming messages. Implements a one-byte addressing scheme,
    with 0xFF as the broadcast address.
    Uses readString() from Stream class to read payload. The Stream class'
    timeout may affect other functuons, like the radio's callback. For an
    created 28 April 2017
    by Tom Igoe
*/

#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <avr/sleep.h>//this AVR library contains the methods that controls the sleep modes
#include <DS3232RTC.h>  //RTC Library https://github.com/JChristensen/DS3232RTC
#include <avr/wdt.h>

#define interruptPin 3 //Pin we are going to use to wake up the Arduino. 

//RTC Module global variables
const int time_interval = 2; // Sets the wakeup intervall in minutes
//int const waterLevelpin = A1; /* The pin used as input for the water level where the potentiometer
//is connected to. */
int timeDelay  =  2500;   // How long to delay the sending of the packet for
int var =  0;   // how many times to send data through LoRa before going to sleep


const int potPin =  A1;


String outgoing;                // outgoing message

byte msgCount  =  0;              // count of outgoing messages
byte localAddress  =  0xBB;       // address of this device
byte destination  =  0xFF;        // destination to send to
long lastSendTime  =  0;          // last send time
int interval  =  100;            // interval between sends


//-----Wake up begin----
void wakeUp() {
  Serial.println("Interrrupt Fired");//Print message to serial monitor
  sleep_disable();//Disable sleep mode
  detachInterrupt(1);   //Removes the interrupt from pin 3;

}
//-----Wake up end---------

//-----Going_To_Sleep begin----
void Going_To_Sleep() {
  sleep_enable();//Enabling sleep mode
  attachInterrupt(1,  wakeUp,  LOW); //attaching a interrupt to pin d3
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);//Setting the sleep mode, in our case full sleep
  //digitalWrite(LED_BUILTIN, LOW); //turning LED off

  time_t t;// creates temp time variable
  t = RTC.get();   //gets current time from rtc
  Serial.println("Sleep  Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //prints time stamp on serial monitor
  delay(1000);   //wait a second to allow the led to be turned off before going to sleep
  sleep_cpu();//activating sleep mode
  Serial.println("just woke up!");//next line of code executed after the interrupt
  //digitalWrite(LED_BUILTIN, HIGH); //turning LED on
  //temp_Humi();//function that reads the temp and the humidity
  t = RTC.get();
  Serial.println("WakeUp Time: " + String(hour(t)) + ":" + String(minute(t)) + ":" + String(second(t))); //Prints time stamp
  //Set New Alarm
  RTC.setAlarm(ALM1_MATCH_MINUTES ,  0,  minute(t) + time_interval,  0,  0);

  // clear the alarm flag
  RTC.alarm(ALARM_1);

}

//-----Going_To_Sleep end----

//------onReceive begin-------

void onReceive(int packetSize)  {
  if  (packetSize  ==  0) return;            // if there's no packet, return

  // read packet header bytes:
  int recipient  =  LoRa.read();            // recipient address
  byte sender  =  LoRa.read();              // sender address
  byte incomingMsgId  =  LoRa.read();       // incoming msg ID
  byte incomingLength  =  LoRa.read();      // incoming msg length

  String incoming  =  "";

  while  (LoRa.available()) {
    incoming  +=  (char)LoRa.read();

  }

  if  (incomingLength  !=  incoming.length()) {
    // check length for error
    Serial.println("error: message length does not match length");
    return;                               // skip rest of function

  }

  // if the recipient isn't this device or broadcast,
  if  (recipient  !=  localAddress  &&  recipient  !=  0xFF) {
    Serial.println("This message is not for me.");
    return;                               // skip rest of function

  }

  // if message is for this device, or broadcast, print details:
  Serial.println("Received from: 0x"  + String(sender,  HEX));
  Serial.println("Sent to: 0x"  + String(recipient,  HEX));
  Serial.println("Message ID: "  + String(incomingMsgId));
  Serial.println("Message length: "  + String(incomingLength));
  Serial.println("Message: "  + incoming);
  Serial.println("RSSI: "  + String(LoRa.packetRssi()));
  Serial.println("Snr: "  + String(LoRa.packetSnr()));
  Serial.println();



  //if(LoRa.parsePacket()!=0){
  //Going_To_Sleep();
  //}
}
//------onReceive end-------


//------sendMessage begin-------
void sendMessage(String outgoing)  {
  LoRa.beginPacket();                     // start packet
  LoRa.write(destination);                // add destination address
  LoRa.write(localAddress);               // add sender address
  LoRa.write(msgCount);                   // add message ID
  LoRa.write(outgoing.length());          // add payload length
  LoRa.print(outgoing);                   // add payload
  LoRa.endPacket();                       // finish packet and send it
  msgCount++;                             // increment message ID
}

//------sendMessage end-------


void setup()  {
  Serial.begin(9600);

  //pinMode(LED_BUILTIN, OUTPUT); //We use the led on pin 13 to indecate when Arduino is A sleep
  //Need to find out how to turn the other green led on the Pro Mini off.
  pinMode(interruptPin, INPUT_PULLUP); //Set pin d2 to input using the buildin pullup resistor
  // digitalWrite(LED_BUILTIN, LOW); //turning LED on
  /// RTC setup

  // initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags
  RTC.setAlarm(ALM1_MATCH_DATE,  0,  0,  0,  1);
  RTC.setAlarm(ALM2_MATCH_DATE,  0,  0,  0,  1);
  RTC.alarm(ALARM_1);
  RTC.alarm(ALARM_2);
  RTC.alarmInterrupt(ALARM_1,  false);
  RTC.alarmInterrupt(ALARM_2,  false);
  RTC.squareWave(SQWAVE_NONE);
  /*
     Uncomment the block block to set the time on your RTC. Remember to comment it again
     otherwise you will set the time at everytime you upload the sketch
  */
  /*/ Begin block
    tmElements_t tm;
    tm.Hour = 19;               // set the RTC to an arbitrary time
    tm.Minute = 02;
    tm.Second = 00;
    tm.Day = 7;
    tm.Month = 2;
    tm.Year = 2019 - 1970;      // tmElements_t.Year is the offset from 1970
    RTC.write(tm);              // set the RTC from the tm structure
    // Block end * */
  time_t t;   //create a temporary time variable so we can set the time and read the time from the RTC
  t = RTC.get(); //Gets the current time of the RTC
  RTC.setAlarm(ALM1_MATCH_MINUTES ,  0,  minute(t) + time_interval,  0,  0); // Setting alarm 1 to go off 5 minutes from now
  // clear the alarm flag
  RTC.alarm(ALARM_1);
  // configure the INT/SQW pin for "interrupt" operation (disable square wave output)
  RTC.squareWave(SQWAVE_NONE);
  // enable interrupt output for Alarm 1
  RTC.alarmInterrupt(ALARM_1,  true);





  // pinMode(A1,INPUT);
  // initialize serial
  while  (!Serial);

  Serial.println("LoRa Duplex");

  // override the default CS, reset, and IRQ pins (optional)
  //LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

  if  (!LoRa.begin(433E6)) {
    LoRa.setTxPower(20);
    // initialize ratio at 915 MHz
    Serial.println("LoRa init failed. Check your connections.");
    while  (true);                         // if failed, do nothing

  }

  Serial.println("LoRa init succeeded.");
}


void loop() {
  delay(100);

  do

    if  (millis()  - lastSendTime  >  interval) {
      String message  =  String (map(analogRead(potPin), 0, 201, 0, 100)); // send a message
      sendMessage(message);
      Serial.println("Sending "  + message);
      lastSendTime  =  millis();              // timestamp the message
      interval  =  random(1000)  + 500;      // 2-3 seconds
      onReceive(LoRa.parsePacket());
      delay(1000);


    }

  while (LoRa.parsePacket() == 0);
  delay(1000);
  LoRa.end();
  delay(1000);
  Going_To_Sleep();   //This function makes the sender go to sleep and wake up after some time


}

The receiver side:

/*RECEIVER
  LoRa Duplex communication
  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.
  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an
  created 28 April 2017
  by Tom Igoe
*/
#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

float oldValue = 0;
float newValue = 0;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

// Connecting to WiFi
String readString;
const char* ssid = "Red de H"; // Here you put your netowrks name
const char* password = "antitesis2019"; // Here you put your network's password
const char* host = "script.google.com";//script.google.com:443/HTTPS
const int httpsPort = 443;
WiFiClientSecure client;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID = “MyGAS";  // Replace by your GAS service id. This is the part of the address of your google script that doesn¡t change.

                String inmessage;
                String oldMessageid;


                const int csPin = 15;          // LoRa radio chip select
                const int resetPin = 16;       // LoRa radio reset
                const int irqPin = 5;         // change for your board; must be a hardware interrupt pin

                String outgoing;              // outgoing message

                byte msgCount = 0;            // count of outgoing messages
                byte localAddress = 0xBB;     // address of this device
                byte destination = 0xFF;      // destination to send to
                long lastSendTime = 0;        // last send time
                int interval = 2000;          // interval between sends

                void sendData(int x, int y)
                {
                client.setInsecure();
                Serial.print("connecting to ");
                Serial.println(host);
                if (!client.connect(host, httpsPort)) {
                Serial.println("connection failed");
                return;
                }
                if (client.verify(fingerprint, host)) {
                Serial.println("certificate matches");
                } else {
                Serial.println("certificate doesn't match");
                }
                String string_x     =  String(x, DEC);
                String string_y     =  String(y, DEC);
                /*This url string below is where you tell google sheets which data and how to add it to
                the sheet. It is woth taking a look at it.
                https://script.google.com/macros/s/yourcodehere/exec?A=1&temperature=2&humidity=3
                */
                String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_x + "&humidity=" + string_y;
                Serial.print("requesting URL: ");
                Serial.println(url);
                client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                "Host: " + host + "\r\n" +
                "User-Agent: BuildFailureDetectorESP8266\r\n" +
                "Connection: close\r\n\r\n");
                Serial.println("request sent");
                while (client.connected()) {
                String line = client.readStringUntil('\n');
                if (line == "\r") {
                Serial.println("headers received");
                break;
                }
                }
                String line = client.readStringUntil('\n');
                if (line.startsWith("{\"state\":\"success\"")) {
                Serial.println("esp8266/Arduino CI successfull!");
                } else {
                Serial.println("esp8266/Arduino CI has failed"); // What does this mean?
                }
                Serial.println("reply was:");
                Serial.println("==========");
                Serial.println(line);
                Serial.println("==========");
                Serial.println("closing connection");
                delay(10000);
                }

                void onReceive(int packetSize) {
                if (packetSize == 0) return;          // if there's no packet, return

                  // read packet header bytes:
                  int recipient = LoRa.read();          // recipient address
byte sender = LoRa.read();            // sender address
byte incomingMsgId = LoRa.read();     // incoming msg ID
byte incomingLength = LoRa.read();    // incoming msg length

String incoming = "";
inmessage = incoming;

while (LoRa.available()) {
  incoming += (char)LoRa.read();
}

if (incomingLength != incoming.length()) {   // check length for error
  Serial.println("error: message length does not match length");
  return;                             // skip rest of function
}

// if the recipient isn't this device or broadcast,
if (recipient != localAddress && recipient != 0xFF) {
  Serial.println("This message is not for me.");
  return;                             // skip rest of function
}

// if message is for this device, or broadcast, print details:
Serial.println("Received from: 0x" + String(sender, HEX));
Serial.println("Sent to: 0x" + String(recipient, HEX));
Serial.println("Message ID: " + String(incomingMsgId));
Serial.println("Message length: " + String(incomingLength));
Serial.println("Message: " + incoming);
Serial.println("RSSI: " + String(LoRa.packetRssi()));
Serial.println("Snr: " + String(LoRa.packetSnr()));
Serial.println();
buttonPushCounter++;
newValue = String(incomingMsgId).toFloat();
inmessage = incoming;
return;

}

void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(msgCount);                 // add message ID
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}



void setup() {
  {
    Serial.begin(9600);                   // initialize serial
    while (!Serial);
    delay(10);
    Serial.println();
    Serial.println(".");
    Serial.println(".");
    Serial.println("LoRa Receiver and post to Google Sheets");
    Serial.println("Setting up Lora Receiver");
    Serial.println(".");
    Serial.println(".");
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);

      Serial.print(".");
    }



    Serial.println("LoRa Duplex");

    // override the default CS, reset, and IRQ pins (optional)
    LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

    if (!LoRa.begin(433E6)) {             // initialize ratio at 915 MHz
      Serial.println("LoRa init failed. Check your connections.");
      while (true);                       // if failed, do nothing
    }

    Serial.println("LoRa init succeeded.");
  }

  LoRa.onReceive(onReceive);
  LoRa.receive();
  Serial.println("LoRa init succeeded.");
}


void loop() {

  do {

    onReceive(LoRa.parsePacket());
    delay(1000);
    if (newValue != oldValue && newValue != 0) {
      delay(1000);
      Serial.println("Sending: ok, got your message");
      int x = inmessage.toInt();
      int y = LoRa.packetRssi();
      for (int j = 0; j < 1; j++) {
        sendData(x, y);
      }
      for (int i = 0; i < 15; i++) {

        delay(1500);
        sendMessage("ok, got ya");
        Serial.print("this is message number");
        Serial.println(i);
      }
    }
    newValue = oldValue;

  } while (LoRa.parsePacket() == 0);
  newValue = oldValue;

}

Ok, so the issue now is that everything works fine for some random amount of time until it stops working and nothing happens at all.

No idea how to proceed

First start looking for hard lockups. Some error in your code that stops the Arduino functioning. Make each side blink the onboard LED in some recognizable pattern. Maybe on for 500ms and off for 1500ms. Or maybe the sender blinks for each packet sent.

If the Arduinos are both blinking OK when the error happens again, you know that the sender is still trying to send and the receiver is still trying to receive. You should be able to plug in to the USB and see what the Arduino is doing. (Depends on the type of Arduino, anything with native USB won't reset when you open the Serial Monitor.)

I still see lots of big delay()s in your code. That is usually going to make any kind of communications fail.

Hi, thanks for your input. I tried to use millis for delays but the Nodemcu v3 does a soft reset. Here is the code.

/*RECEIVER
  LoRa Duplex communication
  Sends a message every half second, and polls continually
  for new incoming messages. Implements a one-byte addressing scheme,
  with 0xFF as the broadcast address.
  Uses readString() from Stream class to read payload. The Stream class'
  timeout may affect other functuons, like the radio's callback. For an
  created 28 April 2017
  by Tom Igoe
*/
#include <Arduino.h>
#include <SPI.h>              // include libraries
#include <LoRa.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000UL;  //the value is a number of milliseconds, ie 1 second

float oldValue = 0;
float newValue = 0;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

// Connecting to WiFi
String readString;
const char* ssid = "Red de H"; // Here you put your netowrks name
const char* password = "antitesis2019"; // Here you put your network's password
const char* host = "script.google.com";//script.google.com:443/HTTPS
const int httpsPort = 443;
WiFiClientSecure client;
const char* fingerprint = "46 B2 C3 44 9C 59 09 8B 01 B6 F8 BD 4C FB 00 74 91 2F EF F6";
String GAS_ID = "";  // Replace by your GAS service id. This is the part of the address of your google script that doesn¡t change.

String inmessage;
String oldMessageid;


const int csPin = 15;          // LoRa radio chip select
const int resetPin = 16;       // LoRa radio reset
const int irqPin = 5;         // change for your board; must be a hardware interrupt pin

String outgoing;              // outgoing message

byte msgCount = 0;            // count of outgoing messages
byte localAddress = 0xBB;     // address of this device
byte destination = 0xFF;      // destination to send to
long lastSendTime = 0;        // last send time
int interval = 2000;          // interval between sends

void sendData(int x, int y)
{
  client.setInsecure();
  Serial.print("connecting to ");
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }
  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  }
  String string_x     =  String(x, DEC);
  String string_y     =  String(y, DEC);
  /*This url string below is where you tell google sheets which data and how to add it to
    the sheet. It is woth taking a look at it.
    https://script.google.com/macros/s/yourcodehere/exec?A=1&temperature=2&humidity=3
  */
  String url = "/macros/s/" + GAS_ID + "/exec?temperature=" + string_x + "&humidity=" + string_y;
  Serial.print("requesting URL: ");
  Serial.println(url);
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");
  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('\n');
  if (line.startsWith("{\"state\":\"success\"")) {
    Serial.println("esp8266/Arduino CI successfull!");
  } else {
    Serial.println("esp8266/Arduino CI has failed"); // What does this mean?
  }
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
  delay(10000);
}

void onReceive(int packetSize) {
  if (packetSize == 0) return;          // if there's no packet, return

  // read packet header bytes:
  int recipient = LoRa.read();          // recipient address
  byte sender = LoRa.read();            // sender address
  byte incomingMsgId = LoRa.read();     // incoming msg ID
  byte incomingLength = LoRa.read();    // incoming msg length

  String incoming = "";
  inmessage = incoming;

  while (LoRa.available()) {
    incoming += (char)LoRa.read();
  }

  if (incomingLength != incoming.length()) {   // check length for error
    Serial.println("error: message length does not match length");
    return;                             // skip rest of function
  }

  // if the recipient isn't this device or broadcast,
  if (recipient != localAddress && recipient != 0xFF) {
    Serial.println("This message is not for me.");
    return;                             // skip rest of function
  }

  // if message is for this device, or broadcast, print details:
  Serial.println("Received from: 0x" + String(sender, HEX));
  Serial.println("Sent to: 0x" + String(recipient, HEX));
  Serial.println("Message ID: " + String(incomingMsgId));
  Serial.println("Message length: " + String(incomingLength));
  Serial.println("Message: " + incoming);
  Serial.println("RSSI: " + String(LoRa.packetRssi()));
  Serial.println("Snr: " + String(LoRa.packetSnr()));
  Serial.println();
  buttonPushCounter++;
  newValue = String(incomingMsgId).toFloat();
  inmessage=incoming;
  return;

}

void sendMessage(String outgoing) {
  LoRa.beginPacket();                   // start packet
  LoRa.write(destination);              // add destination address
  LoRa.write(localAddress);             // add sender address
  LoRa.write(msgCount);                 // add message ID
  LoRa.write(outgoing.length());        // add payload length
  LoRa.print(outgoing);                 // add payload
  LoRa.endPacket();                     // finish packet and send it
  msgCount++;                           // increment message ID
}



void setup() {
  {
    Serial.begin(9600);                   // initialize serial
    while (!Serial);
    delay(10);
    Serial.println();
    Serial.println(".");
    Serial.println(".");
    Serial.println("LoRa Receiver and post to Google Sheets");
    Serial.println("Setting up Lora Receiver");
    Serial.println(".");
    Serial.println(".");
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
      delay(500);

      Serial.print(".");
    }



    Serial.println("LoRa Duplex");

    // override the default CS, reset, and IRQ pins (optional)
    LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin

    if (!LoRa.begin(433E6)) {             // initialize ratio at 915 MHz
      Serial.println("LoRa init failed. Check your connections.");
      while (true);                       // if failed, do nothing
    }

    Serial.println("LoRa init succeeded.");
  }

 LoRa.onReceive(onReceive);
 LoRa.receive();
Serial.println("LoRa init succeeded.");
}


void loop() {
unsigned long currentMillis=millis();
  do {

    onReceive(LoRa.parsePacket());
    //delay(1000);

  if (currentMillis - startMillis >= period)  //test whether the period has elapsed
  {
    if (newValue != oldValue && newValue != 0) {
      delay(1000);
      Serial.println("Sending: ok, got your message");
      int x=inmessage.toInt();
        int y=LoRa.packetRssi();
        for(int j=0;j<1;j++){
          
          
          sendData(x,y);}
      for (int i = 0; i < 15; i++) {
        
        delay(1500);
        sendMessage("ok, got ya");
        Serial.print("this is message number");
        Serial.println(i);
      }
    }
      newValue = oldValue;
      startMillis = currentMillis;  //IMPORTANT to save the start time of the current LED state.
  }
    } while (LoRa.parsePacket() == 0);
    newValue = oldValue;

  }

And the serial monitor outputs:

Soft WDT reset

stack>>>

ctx: cont
sp: 3ffffda0 end: 3fffffc0 offset: 01b0
3fffff50: 00000092 00000000 3ffeecfc 4020492e
3fffff60: 00000000 00000000 3ffeecfc 40204f3f
3fffff70: 3fffdad0 00000000 000017d5 40201776
3fffff80: 3ffe85f3 00000000 3ffeed50 4020545c
3fffff90: 3ffeece4 3ffeecfc 3ffeed50 3ffeedc8
3fffffa0: 3fffdad0 00000000 3ffeed98 40205ecc
3fffffb0: feefeffe feefeffe 3ffe8518 401007d1
<<<stack<<<
H!�ԅ���)8?
.