Sensor node stuck in a sending loop?



  • I am not sure if my sensor node is re-sending a message that the node generated. The messages I see in the console makes me think the node is stuck in a loop resending the same messages. Here is the sketch I am using. This is loaded in a nano and I am using the serial GW sketch to talk to a PI running agocontrol.

    #include <Sleep_n0m1.h>
    #include <SPI.h>
    #include <EEPROM.h>  
    #include <RF24.h>
    #include <Sensor.h>  
    #include <DHT.h>  
    #include <Relay.h>
    
    // Set RADIO_ID to something unique in your sensor network (1-254)
    // or set to AUTO if you want gw to assign a RADIO_ID for you.
    #define RADIO_ID AUTO
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1
    
    #define RELAY_ON 1
    #define RELAY_OFF 0
    
    
    unsigned long SLEEP_TIME = 10; // Sleep time between reads (in seconds)
    long previousMillis = 0;      // will store last time temp data sent
    
    Sensor gw(9, 10);
    DHT dht;
    Sleep sleep;
    
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    
    void setup()  
    { 
      Serial.begin(BAUD_RATE);  // Used to type in characters
      gw.begin(RADIO_ID);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Register all sensors to gw (they will be created as child devices)
      gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
      gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
      
      metric = gw.isMetricSystem();
      // Register all sensors to gw (they will be created as child devices)
      for (int i=0; i<NUMBER_OF_RELAYS;i++) {
    	gw.sendSensorPresentation(RELAY_1+i, S_LIGHT);
      }
    
      // Fetch relay status
      for (int i=0; i<NUMBER_OF_RELAYS;i++) {
    	// Make sure relays are off when starting up
    	digitalWrite(RELAY_1+i, RELAY_OFF);
    	// Then set relay pins in output mode
    	pinMode(RELAY_1+i, OUTPUT);   
    	  
    	// Request/wait for relay status
    	gw.getStatus(RELAY_1+i, V_LIGHT);
    	setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw
      }
    }
    
    void loop()      
    {
      if (gw.messageAvailable()) {
    	message_s message = gw.getMessage(); 
    	setRelayStatus(message);
      }
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > 10000) {
    	// save the last time you blinked the LED 
    	previousMillis = currentMillis;
    	delay(dht.getMinimumSamplingPeriod());
      
    	float temperature = dht.getTemperature();
    	if (isnan(temperature)) {
    		Serial.println("Failed reading temperature from DHT");
    	} else if (temperature) {
    	  lastTemp = temperature;
    	  if (!metric) {
    		temperature = dht.toFahrenheit(temperature);
    	  }
    	  gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
    		Serial.print("T: ");
    		Serial.println(temperature);
    	}
    	
    	float humidity = dht.getHumidity();
    	if (isnan(humidity)) {
    		Serial.println("Failed reading humidity from DHT");
    	} else if (humidity) {
    		lastHum = humidity;
    		gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
    		Serial.print("H: ");
    		Serial.println(humidity);
    	}
    
    	// Power down the radio.  Note that the radio will get powered back up
    	// on the next write() call.
    	delay(1000); //delay to allow serial to fully print before sleep
    	//gw.powerDown();
    	//sleep.pwrDownMode(); //set sleep mode
    	//sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime 
      }
    
    }
    
    
    void setRelayStatus(message_s message) {
      if (message.header.messageType=M_SET_VARIABLE &&
    	  message.header.type==V_LIGHT) {
    	 int incomingRelayStatus = atoi(message.data);
    	 // Change relay state
    	 digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF);
    	 // Write some debug info
    	 Serial.print("Incoming change for relay on pin:");
    	 Serial.print(message.header.childId);
    	 Serial.print(", New status: ");
    	 Serial.println(incomingRelayStatus);
       }
    }
    

    Here is the console logs. Does it look like the sensor node is replying to a message from the GW creating a loop?

    Started sensor.
    Relay=0, distance=1
    Radio id stored in EEPROM was: 2
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=0,ty=17,cr=52: 1.2+
    Sent successfully
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=4,ty=7,cr=14: 0
    Sent successfully
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=0,mt=0,ty=7,cr=65: 1.2+
    Sent successfully
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=1,mt=0,ty=6,cr=226: 1.2+
    Sent successfully
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=255,mt=4,ty=13,cr=206: 
    Sent successfully
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=255,mt=4,t=13,cr=16(ok): I
    Message addressed for this node.
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=0,ty=3,cr=255: 1.2+
    Sent successfully
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=2,ty=2,cr=178: 
    Sent successfully
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1
    Message addressed for this node.
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=2: 1
    Sent successfully
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=87(ok): 0
    Message addressed for this node.
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=101: 0
    Sent successfully
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=3,t=2,cr=230(ok): 1
    Message addressed for this node.
    Incoming change for relay on pin:4, New status: 1
    
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=3,t=2,cr=129(ok): 0
    Message addressed for this node.
    Incoming change for relay on pin:4, New status: 0
    
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=1,mt=1,ty=0,cr=131: 75.2
    Sent successfully
    T: 75.20
    
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=0,mt=1,ty=1,cr=110: 36.0
    Sent successfully
    H: 36.00
    
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=103(ok): 75.2
    Message addressed for this node.
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ec): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=1,mt=3,t=0,cr=0(ev): 75.2
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1
    Message addressed for this node.
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,ty=2,cr=2: 1
    Sent successfully
    Incoming change for relay on pin:4, New status: 1
    
    Message available on pipe 1
    Rx: fr=0,to=2,la=0,ci=4,mt=1,t=2,cr=48(ok): 1
    Message addressed for this node.
    Relaying message back to gateway.
    Tx: fr=2,to=0,la=2,ne=0,ci=4,mt=1,

  • Hero Member

    I dont think its your node,,,but rather thePI/Agocontrol sending the messages repeatedly...Whats the agocontrol set to do??


  • Admin

    Yes, looks like Ago control plugin is replying/sending data to your node.



  • That seems to be the case. If I shutdown the controller, the sensor node does not see the extra replies from the gateway.

    Thanks


Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 6
  • 1
  • 2

5
Online

11.4k
Users

11.1k
Topics

112.7k
Posts