timealerts and mysensors library conflict?



  • hi. im building an irrigation controller that control just 2 24vselenoid valvs with 5 to 12v dc.I know about the other mysesnsors irrigation sensor but mine have all the inteligence on sensor and only need gw for request time the first time that is powered.

    my problem is . if i set time directly on code , time alarms work good . if i request time from GW, alarms won't trigger(just ignored),not even the serial print appear . full sketch compiles without any problem and i check the time received its corrected with serial prints

    anyone know about that issue or is just me?

    
    #define MY_RADIO_NRF24
    
    #include <TimeLib.h>
    #include <SPI.h>
    #include <OneWire.h> 
    #include <DallasTemperature.h>
    #include <MySensors.h>
    #include <TimeAlarms.h>
    
    #define ONE_WIRE_BUS 6 
    OneWire oneWire(ONE_WIRE_BUS); 
    DallasTemperature sensors(&oneWire);
    #define CHILD_ID_MOISTURE 5
    #define CHILD_ID_TEMP 5
    #define CHILD_ID_VALV1 5
    #define CHILD_ID_VALV2 5
    
    #define RELAY_PIN  3  // Arduino Digital I/O pin number for relay  VALV 1 
    #define RELAY_PIN2  5  // Arduino Digital I/O pin number for relay VALV 2
    #define BUTTON_PIN  2  // Arduino Digital I/O pin number for button 
    #define BUTTON_PIN2  7  // Arduino Digital I/O pin number for button 
    #define BUTTON_PIN3  4  // Arduino Digital I/O pin number for button 
    #define BUTTON_PIN4  8  // Arduino Digital I/O pin number for button 
    #define Msensor   14  // moisture sensor A0 pin
    #define LEDR1   15  // LED A1 pin
    #define LEDR2  16 // LED A2 pin
    #define LEDERRO 17  // LED A3  pin
    #define MsPower 18  // LED A4 pin 
    
    
    #define VALVE_TIME 10000UL    //selenoid 1 goes off after () time  (7200000UL)-2HOUR
    #define VALVE_TIME2 10000UL  //selenoid 2 goes off after () time
    #define readtime 3600000UL  //time between read of moisture sensor AND TEMPERATURE (3600000UL)- 1HOUR
    
    
    int frstime;
    int frstimeB;
    int frstimeT;
    int frstimeT1;
    unsigned long startMillis = 0;
    unsigned long startMillis2 = 0;
    unsigned long startMillis3 = 0;
    unsigned long startMillis4 = 0;
    unsigned long startMillisA = 0;
    int buttonState = 0; 
    int buttonState2 = 0; 
    int buttonState3 = 0; 
    int buttonState4 = 0; 
    bool timeReceived = false;
    
    //boolean timeReceived = false;
    unsigned long lastUpdate=0, lastRequest=0;
    
    
    MyMessage msg(CHILD_ID_MOISTURE, V_LEVEL);
    MyMessage msg1(CHILD_ID_TEMP,V_TEMP);
    MyMessage msg2(CHILD_ID_VALV1,V_TRIPPED);
    MyMessage msg3(CHILD_ID_VALV2,V_TRIPPED);
    
    
    void before()
    {
      // Startup up the OneWire library
      sensors.begin();  //DS18B20 LIBRARY START
    }
    
    void setup()  
    {  
    
       // setTime(14,0,0,4,27,17);     IT WORKS IF I UNCOMMENT THAT AND COMMENT  requestTime(receiveTime) further on code;  
          
     //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX
           Alarm.alarmRepeat(14,23,0, onAlarm1);                                              
          Alarm.alarmRepeat(14,23,30, offAlarm1);                 
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX      
      // Setup the button
       pinMode(BUTTON_PIN,INPUT);
       pinMode(RELAY_PIN, OUTPUT);   
       pinMode(RELAY_PIN2, OUTPUT);  
       pinMode(BUTTON_PIN2,INPUT);
       pinMode(BUTTON_PIN3,INPUT);
       pinMode(BUTTON_PIN4,INPUT);
       pinMode(LEDR1, OUTPUT); 
       pinMode(LEDR2, OUTPUT); 
       pinMode(LEDERRO, OUTPUT); 
       pinMode(Msensor, INPUT); 
       pinMode(MsPower, OUTPUT); 
       sensors.begin();  //DS18B20 LIBRARY START
    
    
      // Make sure relays are off when starting up
      digitalWrite(RELAY_PIN,LOW);
       digitalWrite(RELAY_PIN2,LOW);
      // Then set relay pins in output mode
    }
    
    
    
    void presentation()
    {
      sendSketchInfo("irrigation_temp_soilMoisture", "2.0");
      present(CHILD_ID_MOISTURE, S_MOISTURE);
      present(CHILD_ID_TEMP, S_TEMP);
    present(CHILD_ID_VALV1, S_DOOR);
    present(CHILD_ID_VALV2, S_DOOR);
    }
    
    void receiveTime(unsigned long time)
    {
      // Ok, set incoming time 
      setTime(time);
      timeReceived = true;
      digitalWrite(LEDERRO,HIGH);
     wait(500);
     digitalWrite(LEDERRO,LOW);
     Serial.print(year()); 
     }
    
    
     
    void loop() //loop     
    {
      
        digitalClockDisplay();
    
        
      unsigned long now = millis();
       // If no time has been received yet, request it every 10 second from controller
      // When time has been received, request update every hour
      if ((!timeReceived && (now-lastRequest) > (10UL*1000UL))
        || (timeReceived && (now-lastRequest) > (60UL*1000UL*60UL))) {
        // Request time from controller. 
        Serial.println("requesting time");
        requestTime(receiveTime);  
        lastRequest = now;
      }
      
    
    
    /*
    (....CONTROL SELENOIDS AND TEMPERATURE AND MOITURE...IRRELEVANT FOR NOW....)
    */
    
    
    
      }
    
    void digitalClockDisplay()
    {
     // digital clock display of the time
     Serial.print(hour());
     Serial.print(minute());
      Serial.print(second());
     Serial.println();
     Alarm.delay(1000);
    }
    
    void onAlarm1()
      {
      Serial.println("Alarm: - hora de regar");  
     analogWrite(RELAY_PIN,255);    
         
         Alarm.delay(400);
        analogWrite(RELAY_PIN,90);  //decrease voltage(+-5v to 6v) to not burn valve selenoid(hold voltage) 
          digitalWrite(LEDR1,HIGH);
      }
    
    
    void offAlarm1()
      {
      Serial.println("Alarm: - hora de parar ");  
     digitalWrite(RELAY_PIN,  LOW);    
     digitalWrite(LEDR1,LOW);
      }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


  • pretty difficult question hum? lol

    i solve it by forgetting TimeAlarms.h and set just an hour that triggers the solenoid like this
    (HX and MH its the time,[hours] and [minutes] defined at beginning and its set manually)

     if (hour() == HX && minute() == MX )
        {
         analogWrite(RELAY_PIN,255);    
         delay(400);
        analogWrite(RELAY_PIN,90);  //half voltage(+-5v to 6v) to not burn valve selenoid(hold voltage) 
          digitalWrite(LEDR1,HIGH);
          //Serial.print("time up");
       
        }
        else if  (hour() == HXend && minute() == MXend ) 
        {
       digitalWrite(RELAY_PIN,LOW);
       digitalWrite(LEDR1,LOW);
       //Serial.print("time down");
        }
    
    

Log in to reply
 

Suggested Topics

  • 3
  • 5
  • 1
  • 2
  • 6

16
Online

11.4k
Users

11.1k
Topics

112.7k
Posts