Am working on a WiFi based irrigation system that utilises the RF24 lib for comms. Have got prototype of remote sensor up and running which has a standby current of 0.036mA and transmits data every hour using around a peak of 12mA. While running the prototype I see various retry attempts which seem to vary with every transmission – despite the setup being under the same conditions all the time. I have coded a retry loop to limit this to 10 tries connecting to the master – don’t want the sensor to continuously be sending without getting a confirmation from the master
What I am trying to find is the ideal delay required between various RF24 commands to limit transmit times as much as possible to conserve power usage. Any ideas?? (code snippets attached)
pinMode(mostureSensorVCC, OUTPUT);
digitalWrite (mostureSensorVCC, HIGH); //VCC to sensor
pinMode(mostureSensor1, INPUT); //moisture sensor on
delay(10);
int sensorValue1 = analogRead(mostureSensor1); // read the input on analog pin
Serial.print("Current Value Sensor 1 is : "); // debugging
Serial.println(sensorValue1); // print out the value you read:
msg[0] = sensorValue1;
digitalWrite(mostureSensor1, LOW);
digitalWrite(mostureSensorVCC, LOW);
while (message != sensorValue1)
{
Serial.print("sensorValue in while loop is "); // debugging
Serial.println(sensorValue1); // debugging
Serial.print("Message One is "); // debugging
Serial.println(message); // debugging
radio.powerUp();
delay(70);
radio.stopListening();
delay(50);
radio.write(msg, 2);
delay(40);
radio.startListening();
delay(50);
Serial.println(d); // debugging
if (radio.available())
{
Serial.println("Radio available"); // debugging
radio.read(msg, sizeof(msg));
message = msg[0];
Serial.print("Check Message received from master ");// debugging
Serial.println(message);
}
if(d>=10)
{
Serial.println("Unable to send to master");
break;
}
d++;
}
delay(1000);
radio.powerDown();
message = 0;
msg[0] = 0;