Coding issues with LoRa

Hello I am working on a project that requires me to send sensor data attached to arduino to thingspeak. Previously I was using a GSM module but Now I have shifted to LoRa. I have seen some example code like this one

#include <SPI.h>
#include <RH_RF95.h>

RH_RF95 rf95;

#define dht_dpin A0 // Use A0 pin as Data pin for DHT11. 
byte bGlobalErr;
char dht_dat[5]; // Store Sensor Data
char node_id[3] = {1, 1, 1}; //LoRa End Node ID
float frequency = 868.0;
unsigned int count = 1;

void setup()
{
  InitDHT();
  Serial.begin(9600);
  if (!rf95.init())
    Serial.println("init failed");
  // Setup ISM frequency
  rf95.setFrequency(frequency);
  // Setup Power,dBm
  rf95.setTxPower(13);
  rf95.setSyncWord(0x34);

  Serial.println("LoRa End Node Example --");
  Serial.println("    DHT11 Temperature and Humidity Sensor\n");
  Serial.print("LoRa End Node ID: ");

  for (int i = 0; i < 3; i++)
  {
    Serial.print(node_id[i], HEX);
  }
  Serial.println();
}

void InitDHT()
{
  pinMode(dht_dpin, OUTPUT); //Set A0 to output
  digitalWrite(dht_dpin, HIGH); //Pull high A0
}

//Get Sensor Data
void ReadDHT()
{
  bGlobalErr = 0;
  byte dht_in;
  byte i;

  //pinMode(dht_dpin,OUTPUT);
  digitalWrite(dht_dpin, LOW); //Pull Low A0 and send signal
  delay(30);//Delay > 18ms so DHT11 can get the start signal

  digitalWrite(dht_dpin, HIGH);
  delayMicroseconds(40);//Check the high level time to see if the data is 0 or 1
  pinMode(dht_dpin, INPUT);
  // delayMicroseconds(40);
  dht_in = digitalRead(dht_dpin); //Get A0 Status
  //   Serial.println(dht_in,DEC);
  if (dht_in) {
    bGlobalErr = 1;
    return;
  }
  delayMicroseconds(80);//DHT11 send response, pull low A0 80us
  dht_in = digitalRead(dht_dpin);

  if (!dht_in) {
    bGlobalErr = 2;
    return;
  }
  delayMicroseconds(80);//DHT11 send response, pull low A0 80us
  for (i = 0; i < 5; i++) //Get sensor data
    dht_dat[i] = read_dht_dat();
  pinMode(dht_dpin, OUTPUT);
  digitalWrite(dht_dpin, HIGH); //release signal and wait for next signal
  byte dht_check_sum = dht_dat[0] + dht_dat[1] + dht_dat[2] + dht_dat[3]; //calculate check sum
  if (dht_dat[4] != dht_check_sum) //check sum mismatch
  {
    bGlobalErr = 3;
  }
};

byte read_dht_dat() {
  byte i = 0;
  byte result = 0;
  for (i = 0; i < 8; i++)
  {
    while (digitalRead(dht_dpin) == LOW); //wait 50us
    delayMicroseconds(30);//Check the high level time to see if the data is 0 or 1
    if (digitalRead(dht_dpin) == HIGH)
      result |= (1 << (7 - i)); //
    while (digitalRead(dht_dpin) == HIGH); //Get High, Wait for next data sampleing.
  }
  return result;
}
uint16_t calcByte(uint16_t crc, uint8_t b)
{
  uint32_t i;
  crc = crc ^ (uint32_t)b << 8;

  for ( i = 0; i < 8; i++)
  {
    if ((crc & 0x8000) == 0x8000)
      crc = crc << 1 ^ 0x1021;
    else
      crc = crc << 1;
  }
  return crc & 0xffff;
}

uint16_t CRC16(uint8_t *pBuffer, uint32_t length)
{
  uint16_t wCRC16 = 0;
  uint32_t i;
  if (( pBuffer == 0 ) || ( length == 0 ))
  {
    return 0;
  }
  for ( i = 0; i < length; i++)
  {
    wCRC16 = calcByte(wCRC16, pBuffer[i]);
  }
  return wCRC16;
}

void loop()
{
  Serial.print("###########    ");
  Serial.print("COUNT=");
  Serial.print(count);
  Serial.println("    ###########");
  count++;
  ReadDHT();
  char data[50] = {0} ;
  int dataLength = 7; // Payload Length
  // Use data[0], data[1],data[2] as Node ID
  data[0] = node_id[0] ;
  data[1] = node_id[1] ;
  data[2] = node_id[2] ;
  data[3] = dht_dat[0];//Get Humidity Integer Part
  data[4] = dht_dat[1];//Get Humidity Decimal Part
  data[5] = dht_dat[2];//Get Temperature Integer Part
  data[6] = dht_dat[3];//Get Temperature Decimal Part
  switch (bGlobalErr)
  {
    case 0:
      Serial.print("Current humidity = ");
      Serial.print(data[3], DEC);//Show humidity
      Serial.print(".");
      Serial.print(data[4], DEC);//Show humidity
      Serial.print("%  ");
      Serial.print("temperature = ");
      Serial.print(data[5], DEC);//Show temperature
      Serial.print(".");
      Serial.print(data[6], DEC);//Show temperature
      Serial.println("C  ");
      break;
    case 1:
      Serial.println("Error 1: DHT start condition 1 not met.");
      break;
    case 2:
      Serial.println("Error 2: DHT start condition 2 not met.");
      break;
    case 3:
      Serial.println("Error 3: DHT checksum error.");
      break;
    default:
      Serial.println("Error: Unrecognized code encountered.");
      break;
  }

  uint16_t crcData = CRC16((unsigned char*)data, dataLength); //get CRC DATA
  //Serial.println(crcData,HEX);

  Serial.print("Data to be sent(without CRC): ");

  int i;
  for (i = 0; i < dataLength; i++)
  {
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  unsigned char sendBuf[50] = {0};

  for (i = 0; i < dataLength; i++)
  {
    sendBuf[i] = data[i] ;
  }

  sendBuf[dataLength] = (unsigned char)crcData; // Add CRC to LoRa Data
  sendBuf[dataLength + 1] = (unsigned char)(crcData >> 8); // Add CRC to LoRa Data

  Serial.print("Data to be sent(with CRC):    ");
  for (i = 0; i < (dataLength + 2); i++)
  {
    Serial.print(sendBuf[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  rf95.send(sendBuf, dataLength + 2); //Send LoRa Data

  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//Reply data array
  uint8_t len = sizeof(buf);//reply data length

  if (rf95.waitAvailableTimeout(3000))// Check If there is reply in 3 seconds.
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))//check if reply message is correct
    {
      if (buf[0] == node_id[0] && buf[1] == node_id[2] && buf[2] == node_id[2] ) // Check if reply message has the our node ID
      {
        pinMode(4, OUTPUT);
        digitalWrite(4, HIGH);
        Serial.print("Got Reply from Gateway: ");//print reply
        Serial.println((char*)buf);

        delay(400);
        digitalWrite(4, LOW);
        //Serial.print("RSSI: ");  // print RSSI
        //Serial.println(rf95.lastRssi(), DEC);
      }
    }
    else
    {
      Serial.println("recv failed");//
      rf95.send(sendBuf, strlen((char*)sendBuf));//resend if no reply
    }
  }
  else
  {
    Serial.println("No reply, is LoRa gateway running?");//No signal reply
    rf95.send(sendBuf, strlen((char*)sendBuf));//resend data
  }
  delay(30000); // Send sensor data every 30 seconds
  Serial.println("");
}

This is the client side and for the server side the code is : Arduino-Profile-Examples/LG01_ThingSpeak_RESTful_Single_Data.ino at master · dragino/Arduino-Profile-Examples · GitHub

(Had to remove the code as it exceed maximum allowed characters.)

The issue is these are for a single sensor i.e DHT11. I have been trying to alter the code so that I can use multiple sensors like DS18B20, Turbidity sensor, pH sensor but so far I haven't been successful.

Currently I am trying out this code : https://community.thingspeak.com/forum/arduino/please-help/
and I am editing it as per my requirements. If anyone can link me to a forum with a solution to my problem or help me out with the code. I am new to LoRa.

loop() reads the sensor, then populates data with a payload, setting dataLength to the number of bytes
in the payload.

If you want to send more, add more into this payload and set the dataLength to match. The receiving
side will need matching changes to unpack the payload fields.

MarkT:
loop() reads the sensor, then populates data with a payload, setting dataLength to the number of bytes
in the payload.

If you want to send more, add more into this payload and set the dataLength to match. The receiving
side will need matching changes to unpack the payload fields.

I wrote this code but I am output values 0. Please help.

#include <SPI.h>
#include <RH_RF95.h>
#include <SD.h>
#include <OneWire.h> 
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A3
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

#define Turbidity_dpin A0 
#define pH_dpin A1 
#define DO_dpin A2
#define Temperature_dpin A3

RH_RF95 rf95;

const uint8_t pinTurbidity    = A0;
const uint8_t pinPH           = A1;
const uint8_t pinDO           = A2;
const uint8_t pinTemperature  = A3;

byte bGlobalErr;
char Temperature_dat[5];// Store Sensor Data
char Turbidity_dat[5];
char node_id[3] = {1, 1, 1}; //LoRa End Node ID
float frequency = 868.0;
unsigned int count = 1;

void setup()
{
  sensors.begin();
  InitTemperature();
 
  Serial.begin(9600);
  if (!rf95.init())
    Serial.println("init failed");
  // Setup ISM frequency
  rf95.setFrequency(frequency);
  // Setup Power,dBm
  rf95.setTxPower(13);
  rf95.setSyncWord(0x34);

  Serial.println("LoRa End Node Example --");
  Serial.println("   Temperature and Turbidity Sensor\n");
  Serial.print("LoRa End Node ID: ");

  for (int i = 0; i < 3; i++)
  {
    Serial.print(node_id[i], HEX);
  }
  Serial.println();
}

void InitTemperature()
{
  pinMode(Temperature_dpin, OUTPUT); //Set A0 to output
  analogWrite(Temperature_dpin, HIGH); //Pull high A0
}

//Get Sensor Data
void ReadTemperature()
{
  bGlobalErr = 0;
  byte Temperature_in;
  byte i;

  //pinMode(dht_dpin,OUTPUT);
  analogWrite(Temperature_dpin, LOW); //Pull Low A0 and send signal
  delay(30);//Delay > 18ms so DHT11 can get the start signal

  analogWrite(Temperature_dpin, HIGH);
  delayMicroseconds(40);//Check the high level time to see if the data is 0 or 1
  pinMode(Temperature_dpin, INPUT);
  // delayMicroseconds(40);
  Temperature_in = sensors.getTempCByIndex(0); //Get A0 Status
  //   Serial.println(dht_in,DEC);
  if (Temperature_in) {
    bGlobalErr = 1;
    return;
  }
  delayMicroseconds(80);//DHT11 send response, pull low A0 80us
  Temperature_in = sensors.getTempCByIndex(0); 

  if (!Temperature_in) {
    bGlobalErr = 2;
    return;
  }
  delayMicroseconds(80);//DHT11 send response, pull low A0 80us
  for (i = 0; i < 5; i++) //Get sensor data
    Temperature_dat[i] = read_Temperature_dat();
  pinMode(Temperature_dpin, OUTPUT);
  analogWrite(Temperature_dpin, HIGH); //release signal and wait for next signal
  byte Temperature_check_sum = Temperature_dat[0] + Temperature_dat[1] + Temperature_dat[2] + Temperature_dat[3]; //calculate check sum
  if (Temperature_dat[4] != Temperature_check_sum) //check sum mismatch
  {
    bGlobalErr = 3;
  }
};

byte read_Temperature_dat() {
  byte i = 0;
  byte result = 0;
  for (i = 0; i < 8; i++)
  {
    while (analogRead(Temperature_dpin) == LOW); //wait 50us
    delayMicroseconds(30);//Check the high level time to see if the data is 0 or 1
    if (analogRead(Temperature_dpin) == HIGH)
      result |= (1 << (7 - i)); //
    while (analogRead(Temperature_dpin) == HIGH); //Get High, Wait for next data sampleing.
  }
  return result;
}

void Init()
{
  pinMode(Turbidity_dpin, OUTPUT); //Set A0 to output
  analogWrite(Turbidity_dpin, HIGH); //Pull high A0
}

//Get Sensor Data
void ReadTurbidity()
{
  bGlobalErr = 0;
  int Turbidity_in;
  byte Turbidity_or;
  byte i;

  //pinMode(Turbidity_dpin,OUTPUT);
  analogWrite(Turbidity_dpin, LOW); //Pull Low A0 and send signal
  delay(30);//Delay > 18ms so Turbidity11 can get the start signal

  analogWrite(Turbidity_dpin, HIGH);
  delayMicroseconds(40);//Check the high level time to see if the data is 0 or 1
  pinMode(Turbidity_dpin, INPUT);
  // delayMicroseconds(40);
  Turbidity_or = analogRead(Turbidity_dpin); //Get A0 Status
  float voltage = Turbidity_or * (5.0 / 1024.0);
  Turbidity_in = ((-1120.4*voltage*voltage)+(5742.3*voltage)-(4352.9)); 
  //   Serial.println(Turbidity_in,DEC);
  if (Turbidity_in) {
    bGlobalErr = 1;
    return;
  }
  delayMicroseconds(80);//Turbidity11 send response, pull low A0 80us
  Turbidity_in = analogRead(Turbidity_dpin);

  if (!Turbidity_in) {
    bGlobalErr = 2;
    return;
  }
  delayMicroseconds(80);//Turbidity11 send response, pull low A0 80us
  for (i = 0; i < 5; i++) //Get sensor data
    Turbidity_dat[i] = read_Turbidity_dat();
  pinMode(Turbidity_dpin, OUTPUT);
  analogWrite(Turbidity_dpin, HIGH); //release signal and wait for next signal
  byte Turbidity_check_sum = Turbidity_dat[0] + Turbidity_dat[1] + Turbidity_dat[2] + Turbidity_dat[3]; //calculate check sum
  if (Turbidity_dat[4] != Turbidity_check_sum) //check sum mismatch
  {
    bGlobalErr = 3;
  }
};

byte read_Turbidity_dat() {
  byte i = 0;
  byte result = 0;
  for (i = 0; i < 8; i++)
  {
    while (analogRead(Turbidity_dpin) == LOW); //wait 50us
    delayMicroseconds(30);//Check the high level time to see if the data is 0 or 1
    if (analogRead(Turbidity_dpin) == HIGH)
      result |= (1 << (7 - i)); //
    while (analogRead(Turbidity_dpin) == HIGH); //Get High, Wait for next data sampleing.
  }
  return result;
}
uint16_t calcByte(uint16_t crc, uint8_t b)
{
  uint32_t i;
  crc = crc ^ (uint32_t)b << 8;

  for ( i = 0; i < 8; i++)
  {
    if ((crc & 0x8000) == 0x8000)
      crc = crc << 1 ^ 0x1021;
    else
      crc = crc << 1;
  }
  return crc & 0xffff;
}

uint16_t CRC16(uint8_t *pBuffer, uint32_t length)
{
  uint16_t wCRC16 = 0;
  uint32_t i;
  if (( pBuffer == 0 ) || ( length == 0 ))
  {
    return 0;
  }
  for ( i = 0; i < length; i++)
  {
    wCRC16 = calcByte(wCRC16, pBuffer[i]);
  }
  return wCRC16;
}

Code continued in next post.

void loop()
{
  Serial.print("###########    ");
  Serial.print("COUNT=");
  Serial.print(count);
  Serial.println("    ###########");
  count++;
  ReadTemperature();
  ReadTurbidity();
  char data[50] = {0} ;
  int dataLength = 7; // Payload Length
  // Use data[0], data[1],data[2] as Node ID
  data[0] = node_id[0] ;
  data[1] = node_id[1] ;
  data[2] = node_id[2] ;
  data[3] = Temperature_dat[0];//Get Temperature Integer Part
  data[4] = Temperature_dat[1];//Get Temperature Decimal Part
  data[5] = Turbidity_dat[2];//Get Temperature Integer Part
  data[6] = Turbidity_dat[3];//Get Temperature Decimal Part
  switch (bGlobalErr)
  {
    case 0:
      Serial.print("Current Temperature = ");
      Serial.print(data[3], DEC);//Show humidity
      Serial.print(".");
      Serial.print(data[4], DEC);//Show humidity
      Serial.print("C  ");
      Serial.print("turbidity = ");
      Serial.print(data[5], DEC);//Show temperature
      Serial.print(".");
      Serial.print(data[6], DEC);//Show temperature
      Serial.println("NTU  ");
      break;
    case 1:
      Serial.println("Error 1: Temeprature start condition 1 not met.");
      break;
    case 2:
      Serial.println("Error 2: Temperature start condition 2 not met.");
      break;
    case 3:
      Serial.println("Error 3: checksum error.");
      break;
    default:
      Serial.println("Error: Unrecognized code encountered.");
      break;
  }

  uint16_t crcData = CRC16((unsigned char*)data, dataLength); //get CRC DATA
  //Serial.println(crcData,HEX);

  Serial.print("Data to be sent(without CRC): ");

  int i;
  for (i = 0; i < dataLength; i++)
  {
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  unsigned char sendBuf[50] = {0};

  for (i = 0; i < dataLength; i++)
  {
    sendBuf[i] = data[i] ;
  }

  sendBuf[dataLength] = (unsigned char)crcData; // Add CRC to LoRa Data
  sendBuf[dataLength + 1] = (unsigned char)(crcData >> 8); // Add CRC to LoRa Data

  Serial.print("Data to be sent(with CRC):    ");
  for (i = 0; i < (dataLength + 2); i++)
  {
    Serial.print(sendBuf[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  rf95.send(sendBuf, dataLength + 2); //Send LoRa Data

  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//Reply data array
  uint8_t len = sizeof(buf);//reply data length

  if (rf95.waitAvailableTimeout(3000))// Check If there is reply in 3 seconds.
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))//check if reply message is correct
    {
      if (buf[0] == node_id[0] && buf[1] == node_id[2] && buf[2] == node_id[2] ) // Check if reply message has the our node ID
      {
        pinMode(4, OUTPUT);
        digitalWrite(4, HIGH);
        Serial.print("Got Reply from Gateway: ");//print reply
        Serial.println((char*)buf);

        delay(400);
        digitalWrite(4, LOW);
        //Serial.print("RSSI: ");  // print RSSI
        //Serial.println(rf95.lastRssi(), DEC);
      }
    }
    else
    {
      Serial.println("recv failed");//
      rf95.send(sendBuf, strlen((char*)sendBuf));//resend if no reply
    }
  }
  else
  {
    Serial.println("No reply, is LoRa gateway running?");//No signal reply
    rf95.send(sendBuf, strlen((char*)sendBuf));//resend data
  }
  delay(30000); // Send sensor data every 30 seconds
  Serial.println("");
}

abc53:
I wrote this code but I am output values 0. Please help.

Not sure many of us understand what that means.

  • I am getting output as 0. The thingspeak channel shows that both the temperature and turbidity value is 0

What do your debug prints show?

It just increases the count and outputs HEX data for temperature and turbidity. but both values are something like 1 1 1 0 0 0 and 1 1 1 0 57 96. something like this

abc53:
It just increases the count and outputs HEX data for temperature and turbidity. but both values are something like 1 1 1 0 0 0 and 1 1 1 0 57 96. something like this

What is "IT"? Is it correct? It means nothing to us.

You need to trace the data all the way through the chain to find out where it's getting blocked or corrupted. Start with the raw sensor readings and trace it through ever step from LoRa TX to LoRA Rx to Thingspeak. Check it with debug prints at every hand off. That's how you debug code on Arduino. It's your project so it's your job.

You are sharing the bGlobalErr flag between two sensors, so if the first one fails you won't
know about it.

What's the receive side doing with the packet?

The packet should print the same on tx and rx sides. Remember to check for any
error conditions (for instance you don't check the bool result of rh95.send()), you must
always check all possible errors in comms code or you'll get into a really confused state.

This is the updated code, but for some reason I am unable to get the decimal values from the sensors. Please help

#include <SPI.h>
#include <RH_RF95.h>
#include <SD.h>
#include <OneWire.h> 
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A3
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

#define SensorPin A1          //pH meter Analog output to Arduino Analog Input 1
#define Turbidity_dpin A0 
#define pH_dpin A1 
#define DO_dpin A2
#define Temperature_dpin A3

RH_RF95 rf95;

const uint8_t pinTurbidity    = A0;
const uint8_t pinPH           = A1;
const uint8_t pinDO           = A2;
const uint8_t pinTemperature  = A3;

uint16_t datatemperature = 0;
int dataturbidity = 0;


unsigned long int avgValue;  //Store the average value of the sensor feedback
float b;
int tuf[10],temp;


byte bGlobalErr;
float Temperature_dat[4];// Store Sensor Data
float Turbidity_dat[3];
float pH_dat[4];
char node_id[3] = {1, 1, 1}; //LoRa End Node ID
float frequency = 868.0;
unsigned int count = 1;

void setup()
{
  sensors.begin();
 
 
  Serial.begin(9600);
  if (!rf95.init())
    Serial.println("init failed");
  // Setup ISM frequency
  rf95.setFrequency(frequency);
  // Setup Power,dBm
  rf95.setTxPower(13);
  rf95.setSyncWord(0x34);

  Serial.println("LoRa End Node Example --");
  Serial.println("   Temperature and Turbidity Sensor\n");
  Serial.print("LoRa End Node ID: ");

  for (int i = 0; i < 3; i++)
  {
    Serial.print(node_id[i], HEX);
  }
  Serial.println();
}


void loop()

{
  int i;
  for (i = 0; i < 5; i++){
   sensors.requestTemperatures();
  Temperature_dat[i]= sensors.getTempCByIndex(0);}
  int Turbidity_or;
 

 for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
  { 
    tuf[i]=analogRead(SensorPin);
    delay(10);
  }
  for(int i=0;i<9;i++)        //sort the analog from small to large
  {
    for(int j=i+1;j<10;j++)
    {
      if(tuf[i]>tuf[j])
      {
        temp=tuf[i];
        tuf[i]=tuf[j];
        tuf[j]=temp;
      }
    }
  }
  avgValue=0;
  for(int i=2;i<8;i++)                      //take the average value of 6 center sample
    avgValue+=tuf[i];
  float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
  pH_dat[0]= float(3.5*phValue); 
 // pH_dat[1]= getDecimal(3.5*phValue); 





delay(100);
  Turbidity_or = analogRead(Turbidity_dpin); //Get A0 Status
  float voltage = Turbidity_or * (5.0 / 1024.0);
   Turbidity_dat[1]= ((-1120.4*voltage*voltage)+(5742.3*voltage)-(4352.9)); 
delay(100);
   
  Serial.print("###########    ");
  Serial.print("COUNT=");
  Serial.print(count);
  Serial.println("    ###########");
  count++;
  char data[50] = {0} ;
  int dataLength = 6; // Payload Length
  // Use data[0], data[1],data[2] as Node ID
  data[0] = node_id[0] ;
  data[1] = node_id[1] ;
  data[2] = node_id[2] ;
  data[3] = Temperature_dat[0];
 // data[4] = Temperature_dat[1];//Get Temperature Integer Part
  data[4] = Turbidity_dat[1];//Get Temperature Decimal Part
  data[5] = pH_dat[0];
  //data[7] = pH_dat[1];
  //Get Temperature Decimal Part

  rf95.send(data, sizeof(data));


      Serial.print(" Current Temperature = ");
      Serial.print(data[3], DEC);//Show humidity
     // Serial.print(".");
      //Serial.print(data[4], DEC);//Show humidity
      Serial.print(" C  ");
      delay(300);
      Serial.print(" Current Turbidity = ");
      Serial.print(data[4], DEC);//Show humidity
      Serial.print(" NTU");
      delay(300);
      Serial.print(" pH = ");
      Serial.print(data[5], DEC);//Show humidity
    //  Serial.print(data[7], DEC);//Show humidity
}

OUTPUT -

LoRa End Node Example --
   Temperature and Turbidity Sensor

LoRa End Node ID: 111
###########    COUNT=1    ###########
 Current Temperature = 24 C   Current Turbidity = 92 NTU pH = 3###########    COUNT=2    ###########
 Current Temperature = 24 C   Current Turbidity = 92 NTU pH = 3###########    COUNT=3    ###########
 Current Temperature = 24 C   Current Turbidity = 92 NTU pH = 3###########    COUNT=4    ###########
 Current Temperature = 24 C   Current Turbidity = 85 NTU pH = 3###########    COUNT=5    ###########
 Current Temperature = 24 C   Current Turbidity = 88 NTU pH = 3###########    COUNT=6    ###########
 Current Temperature = 24 C   Current Turbidity = 88 NTU pH = 3###########    COUNT=7    ###########
 Current Temperature = 24 C   Current Turbidity = 92 NTU pH = 3###########    COUNT=8    ###########
 Current Temperature = 24 C   Current Turbidity = 92 NTU pH = 3###########    COUNT=9    ###########

Did you check the Serial.print reference ?

https://www.arduino.cc/en/serial/print

Even after rectifying that , the data I am getting at the server side ( Thingspeak channel) does not have decimal values. Code for the server side. -

  /*
  Upload Data to IoT Server ThingSpeak (https://thingspeak.com/):
  Support Devices: LG01 
  
  Example sketch showing how to get data from remote LoRa node, 
  Then send the value to IoT Server
  It is designed to work with the other sketch dht11_client. 
  modified 24 11 2016
  by Edwin Chen <support@dragino.com>
  Dragino Technology Co., Limited
*/

#include <SPI.h>
#include <RH_RF95.h>
#include <Console.h>
#include "ThingSpeak.h"
#include "YunClient.h"
YunClient client;
RH_RF95 rf95;

//If you use Dragino IoT Mesh Firmware, uncomment below lines.
//For product: LG01. 
#define BAUDRATE 115200

unsigned long myChannelNumber = XXXXX;
const char * myWriteAPIKey = "XXXXXXXX";
const char * myReadAPIKey = "XXXXXXX";
uint16_t crcdata = 0;
uint16_t recCRCData = 0;
float frequency = 868.0;

void setup()
{
    Bridge.begin(BAUDRATE);
    //Console.begin();// Don't use Console here, since it is conflict with the ThinkSpeak library. 

    ThingSpeak.begin(client);
    
    if (!rf95.init())
        //Console.println("init failed");
    ;
    // Setup ISM frequency
    rf95.setFrequency(frequency);
    // Setup Power,dBm
    rf95.setTxPower(13);
    
    //Console.println("Start Listening ");
}
void loop()
{

    if (rf95.waitAvailableTimeout(2000))// Listen Data from LoRa Node
    {
        uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];//receive data buffer
        uint8_t len = sizeof(buf);//data buffer length
        if (rf95.recv(buf, &len))//Check if there is incoming data
        {
                //Console.println("Get Data from LoRa Node");
                if(buf[0] == 1||buf[1] == 1||buf[2] ==1) //Check if the ID match the LoRa Node ID
                {
                    uint8_t data[] = "   Server ACK";//Reply 
                    data[0] = buf[0];
                    data[1] = buf[1];
                    data[2] = buf[2];
                    rf95.send(data, sizeof(data));// Send Reply to LoRa Node
                    rf95.waitPacketSent();
                    int newData[4] = {0, 0, 0, 0}; //Store Sensor Data here
                    for (int i = 0; i < 3; i++)
                    {
                        newData[i] = buf[i + 3];
                    }
                    int h = newData[0];
                    int t = newData[1];
                    int b = newData[2];
                    
                    ThingSpeak.setField(1,h); // 
                    ThingSpeak.setField(2,t);
                    ThingSpeak.setField(3,b);
                    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);   // Send Data to IoT Server.
                }
            }       
         }
         else
         {
              //Console.println("recv failed");
              ;
          }
     }

Hello there, I have used this sniffer code that has altering Spreading Factor, bandwidth and frequency. the change is operational although it doesn't capture any packets and i have a raspberry pi transmitting constantly right next to it. I am using the Radio Head Library. the two devices are on the same spreading factor frequency and bandwidth

i have tried various other alternatives but with no luck. It operates and can send packets to TTN from both devices so they're both functional. They both have an antenna and use the Dragino shield

My pins and includes

#include <SPI.h>
#include <RH_RF95.h>
#include <stdio.h>
#include <stdarg.h>
#define LED 8

#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
Singleton instance of the radio driver

RH_RF95 rf95(RFM95_CS, RFM95_INT);
The different variables i would like to display

uint8_t _rxBuffer[RH_RF95_MAX_MESSAGE_LEN]; // receive buffer
uint8_t _rxRecvLen; // number of bytes actually received
char _printBuffer[512] = "\ // to send output to the PC
Configure pins

pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
// The RFM95 has a pulldown on this pin, so the radio
// is technically always selected unless you set the pin low
// this will cause other SPI devices to fail to function as
// expected because CS (active-low) will be selected for
// the RFM95 at the same time.
digitalWrite(RFM95_CS, HIGH);

pinMode(LED, OUTPUT);
Initialize Serial

Serial.begin(115200);
delay(100);
Serial.println(F("LoRa Network Probe"));
Initialize Radio

digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
Check if everything works

while (!rf95.init())
{

Serial.println(F("Failed"));
while (1);
}

Serial.println(F("Lora init Works"));
Set the frequencies the spreading factor and bandwidth

rf95_setFrequency(_freqIndex);
rf95.setCodingRate4(5);
rf95.setSpreadingFactor(7);
rf95.setSignalBandwidth(250000);
rf95.setCodingRate4(5);
//rf95_setBandwidth(_bwIndex);
//rf95_setSpreadingFactor(_sfIndex);
Serial.print(F(" ("));
Serial.print(_packetCounts[_freqIndex][_bwIndex][_sfIndex]);
Serial.println(F(")"));
rf95.setPromiscuous(true);

}
Start The loop required to run check for receive and then do the following tasks.

void loop()
{
_rxRecvLen = sizeof(_rxBuffer);

digitalWrite(LED, LOW);

rf95.setModeRx();

// Handle incoming packet if available
if (rf95.recv(_rxBuffer, &_rxRecvLen))
{
char isAck[4] = { " " };

digitalWrite(LED, HIGH);

_packetCounts[_freqIndex][_bwIndex][_sfIndex]++;

if (rf95.headerFlags() & RH_FLAGS_ACK)
{
memcpy(isAck, "Ack\0", 3);
}

_rxBuffer[_rxRecvLen] = '\0';

Serial.println(millis());

Serial.print(F("Signal(RSSI)= "));
Serial.print(rf95.lastRssi(), DEC);
Serial.print(F(" (Freq: "));
Serial.print((uint32_t)(_frequencies[_freqIndex] * 10), DEC);
Serial.println(F(")"));

Serial.print(F(" "));
Serial.print(rf95.headerFrom(), DEC);
Serial.print(F(" >> "));
Serial.print(rf95.headerTo(), DEC);
Serial.print(F(" MsgId:"));
Serial.print(rf95.headerId(), DEC);
Serial.print(F(" Flags:"));
Serial.print(rf95.headerFlags(), HEX);
Serial.print(F(" "));
Serial.println(isAck);

Serial.print(F(" "));
Serial.print(_rxRecvLen, DEC);
Serial.print(F(" => "));
Serial.println((char*)_rxBuffer);

for (int i = 0; i < _rxRecvLen; i++)
{
snprintf(_printBuffer, sizeof(_printBuffer), "%s %02X", _printBuffer, _rxBuffer*);*
Serial.print(rxBuffer*, HEX);
_
Serial.print(" ");*

* }*
Serial.println((char*)_rxBuffer);
* Serial.print(F(" ("));*
* Serial.print(_packetCounts[_freqIndex][_bwIndex][sfIndex]);
_
Serial.println(F(")"));*