Project

General

Profile

Payloads gets missing

Added by Alban_T 3 months ago

Hi,

I recently dug up my Jeenodes to do some remote temperature measuring. I got it working but I notice that the interval at which I recieve the packages is not consistent.
My sending sketch send every 10 seconds and my receiving sketch receives it every 117500ms so that is almost 10seconds. But when I move the sending jeenode further away it seems the signal gets very weak very fast.
Currently the distance between my jeenodes is about 10m both inside my house (hope to move one outside my house) and the receiving interval is somewhere between 11750ms and 3 times that indicating that quite some packeteg are lost in the ether :(
When I move outside 99% gets lost :(
What could be the issue here?
Could someone have a quick look at my sketches and advise me on how I can improve them in hope to increase the reliability.

Sending:

#include <JeeLib.h>
#include <avr/sleep.h>
#define myNodeID 1      // RF12 node ID in the range 1-30
#define network 212      // RF12 Network group
#define freq RF12_868MHZ // Frequency of RFM12B module

const int  minutes = 1; // Duration of sleep between measurements, in minutes
const int debugging = 1;

#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
// powerline for the SHT = tempPower!!!!
const int dataPin = 6;  // DIO3 on the JeeNode
const int clockPin = A2;  // AIO3 on the JeeNode
SHT1x sht1x(dataPin, clockPin);
float Temp_SHT;
float RV_SHT;

// interrupt handler for JeeLabs Sleepy power saving
ISR(WDT_vect) { Sleepy::watchdogEvent(); }  
byte myId;  // remember my own node ID

const int LEDpin = 4; // a LED is connected between DIO1 and GND on the JeeNode
//########################################################################################################################
//Data Structure to be sent, it is variable in size and we only send 2+n*2 bytes where n is the number of DS18B20 sensors attached
//########################################################################################################################
typedef struct {
    int supplyV;  // Supply voltage
    int temp; // Temperature reading
    int humi; // Humidity reading
} Payload;
Payload temptx;
//########################################################################################################################

void setup() {
    Serial.begin(57600);
    Serial.println("SHT_send.ino");

    // Initialize RFM12 with settings defined above
    rf12_initialize(myNodeID,freq,network);
    myId = rf12_config(); // Initialize RFM12 with its internal settings

    rf12_control(0xC00B); // Adjust low battery voltage to 2.2V
    rf12_sleep(0);  // Put the RFM12 to sleep
    PRR = bit(PRTIM1);  // only keep timer 0 going
    ADCSRA &= ~ bit(ADEN);  // Disable the ADC
    bitSet (PRR, PRADC);  // Power down ADC
    bitClear (ACSR, ACIE);  // Disable comparator interrupts
    bitClear (ACSR, ACD); // Power down analogue comparator

    pinMode(LEDpin, OUTPUT);  // Set the LEDpin as an output
    FlashLED(50); // Flash the LED to confirm that Setup has executed
}

void loop() {
    digitalWrite(LEDpin, 1);  // turn the LED on to signal a measurement and transmission

    //SHT11 readings:
    temptx.temp = (sht1x.readTemperatureC() * 100);
    temptx.humi = sht1x.readHumidity();

    vccRead();  // Read current supply voltage

    rfwrite();  // Send data via RF

    digitalWrite(LEDpin, 0);  // Turn the LED off after transmission

    for(byte j = 0; j < minutes; j++) 
    { // Sleep for x minutes
        if (debugging == 1) {
            Sleepy::loseSomeTime(10000);  //JeeLabs power save function: enter low power mode for 60 seconds (valid range 16-65000 ms)
        }
        else {
            Sleepy::loseSomeTime(60000*15);  //JeeLabs power save function: enter low power mode for 60 seconds (valid range 16-65000 ms)
        }
    }
}

//--------------------------------------------------------------------------------------------------
// Send payload data via RF
//--------------------------------------------------------------------------------------------------
static void rfwrite(){
        rf12_sleep(RF12_WAKEUP);
        rf12_sendNow(RF12_HDR_ACK, &temptx, sizeof temptx);
        rf12_sendWait(2);
        rf12_sleep(RF12_SLEEP);
}


//--------------------------------------------------------------------------------------------------
// Flash the LED for an amount of ms
//--------------------------------------------------------------------------------------------------
void FlashLED(int ms){
    digitalWrite(LEDpin, 1);  // turn LED on
    Sleepy::loseSomeTime(ms); // wait for x ms
    digitalWrite(LEDpin, 0);  // turn LED off
}




//--------------------------------------------------------------------------------------------------
// Reads current voltage
//--------------------------------------------------------------------------------------------------
void vccRead(){
    bitClear(PRR, PRADC); // power up the ADC
    ADCSRA |= bit(ADEN);  // enable the ADC
    Sleepy::loseSomeTime(10); // wait for 10ms
    temptx.supplyV = map(analogRead(6), 0, 1023, 0, 660); // read the voltage
    ADCSRA &= ~ bit(ADEN);  // disable the ADC
    bitSet(PRR, PRADC); // power down the ADC
}

Recieving:

//#define RF69_COMPAT 1 // define this to use Jeelink instead of the jeenode
#include <JeeLib.h>
#define myNodeID 2      // RF12 node ID in the range 1-30
#define network 212      // RF12 Network group
#define freq RF12_868MHZ // Frequency of RFM12B module
//########################################################################################################################
//Data Structure to be received
//########################################################################################################################
typedef struct {
    int supplyV;  // Supply voltage
    int temp; // Temperature reading
    int humi; // Humidity reading
} Payload;
Payload temptx;

long prevMillis;
long currMillis;
long diffMillis;

const int LEDpin = 4; // a LED is connected between DIO1 and GND on the JeeNode
void setup(){
    Serial.begin(57600);
    Serial.println("SHT_receive.ino");
    rf12_initialize(myNodeID,freq,network);
    pinMode(LEDpin, OUTPUT); // Set the LEDpin as an output
    digitalWrite(LEDpin, 1); // turn LED on
    delay(500);
    digitalWrite(LEDpin, 0); // turn LED off
    prevMillis = millis();
    currMillis = millis();
    diffMillis = currMillis - prevMillis;
}
void loop(){
   if (rf12_recvDone() && rf12_crc == 0){
      digitalWrite(LEDpin, 1);  // turn LED on

      int numSensors = rf12_len/2 - 1;
      const Payload* p = (const Payload*) rf12_data;

      currMillis = millis();
      diffMillis = currMillis - prevMillis;
      prevMillis = currMillis;

      Serial.print(currMillis); Serial.print("    ");
      Serial.print(diffMillis); Serial.print("    ");
      Serial.print("Voltage: "); Serial.print(p->supplyV / 100.); Serial.print("V ");
      Serial.print("temp1: "); Serial.print(p->temp / 100.); Serial.print(" C ");
      Serial.print("RV: "); Serial.print(p->humi); Serial.println("%");

      digitalWrite(LEDpin, 0);  // turn LED off
   }
}

Replies (2)

RE: Payloads gets missing - Added by Rolf 3 months ago

Hi,
the difference between 10000 ms (sender is sleeping in low power mode) and 117500 ms (interval between packages received) may be due to the time needed to readout the SHT11.

A distance of 10 meters between jeenodes is no problem, if you have free sight between them. Inside the house there should be no more then 2 walls inbetween. With ferroconcrete walls the situation may be worse. I have experience with a house with half-timbered walls. Inside the house: Distance of appr. 10 meters is OK, but not more than two walls. For nodes outside I have installed al relay. They cannot reach the receiving node directly.

Greetings,
Rolf

RE: Payloads gets missing - Added by martynj 28 days ago

Do you have access to an RFM69 module (e.g. JeeLink 3vc) - running the standard rf12demo gives an RSSI value and if you turn off quiet mode will show if there is competing traffic on the channel.

    (1-2/2)