Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. vickey
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    vickey

    @vickey

    3
    Reputation
    24
    Posts
    937
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    vickey Follow

    Best posts made by vickey

    • RE: Interrupt, Perform a specific function, not the loop

      Here is my sketch if someone finds it useful. It uses LDR to set night mode in low light conditions and vice versa, door reed switch and PIR sensor to turn ac or dc lights with the help of two channel relay and EasyIOT as server. Interrupts perform the functions of turning lights on and off while timer wake up decides the night mode implementation. Moreover, sensor node sleeps most of its time to conserve the battery.

      #include <SPI.h>
      #include <MySensor.h>
      
      #define CHILD_ID_LIGHT 0
      #define CHILD_ID_DOOR 1
      #define CHILD_ID_PIR 2
      #define CHILD_ID_LED 3
      #define CHILD_ID_SAVER 4
      
      #define LDR_PIN A0
      #define DOOR_PIN 2
      #define PIR_PIN 3
      #define LED_PIN 4 // Relay 1 is attached
      #define SAVER_PIN 5 // Relay 2 is attached
      
      #define INTERRUPT DOOR_PIN-2
      
      unsigned long SLEEP_TIME = 1200000; // Sleep time 1200000 i.e. 20 minutes (in milliseconds)
      
      MySensor gw;
      
      boolean activity = false;
      boolean LEDSwitch = false;
      boolean SaverSwitch = false;
      boolean nightSwitch = false;
      
      MyMessage msgLDR(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      MyMessage msgDoor(CHILD_ID_DOOR, V_TRIPPED);
      MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED);
      
      void setup()  
      { 
        gw.begin(NULL, AUTO, false, 1);
        gw.sendSketchInfo("BedRoom", "1.2");
        
        pinMode(DOOR_PIN,INPUT);
        pinMode(PIR_PIN,INPUT);
        pinMode(LED_PIN, OUTPUT);
        pinMode(SAVER_PIN, OUTPUT);
        
        digitalWrite(DOOR_PIN, HIGH);
        digitalWrite(PIR_PIN, HIGH);
        digitalWrite(LED_PIN, HIGH);
        digitalWrite(SAVER_PIN, HIGH);
        
        gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        gw.present(CHILD_ID_DOOR, S_DOOR);
        gw.present(CHILD_ID_PIR, S_MOTION);
        
        int LightLevel;
        for(int i = millis(); i < (millis() + 5000); i++){
          LightLevel = (100 - ((1023-analogRead(LDR_PIN))/10.23));
        }
        if(LightLevel < 20){
          gw.send(msgLDR.set(LightLevel));
          nightSwitch = true;
        }
        else {
          gw.send(msgLDR.set(LightLevel));
          nightSwitch = false;
        }
      }
      
      void loop()      
      {
        if(nightSwitch){ //When night switch is on
          int wake;
          wake = gw.sleep(INTERRUPT,FALLING, SLEEP_TIME);
          if(wake == 1){
            if(!activity){
              gw.send(msgDoor.set("1"));
              gw.send(msgDoor.set("0"));
              activity = true;
              if((!LEDSwitch) && (!SaverSwitch)){
                pirswitch();
              }
              else{ //activity finished
              activityoff();
              }
            }
          }
          else{ //Timer wake up
            int LightLevel;
            if((!LEDSwitch) && (!SaverSwitch)){
              for(int i = millis(); i < (millis() + 5000); i++){
                LightLevel = (100 - ((1023-analogRead(LDR_PIN))/10.23));
              }
            }
            else{
              for(int i = millis(); i < (millis() + 1000); i++){
                LightLevel = (100 - ((1023-analogRead(LDR_PIN))/10.23));
              }
            }
              
            if((LightLevel < 10) && ((!LEDSwitch) && (SaverSwitch))){
              Serial.println("Light level is less than 50%, Turning LED on");
              digitalWrite(LED_PIN, LOW);
              LEDSwitch = true;
              SLEEP_TIME = 7200000; // Sleep time changed to 2 hours
            }
            else if((LightLevel > 20) && ((!LEDSwitch) && (!SaverSwitch))){
              gw.send(msgLDR.set(LightLevel));
              nightSwitch = false;
              SLEEP_TIME = 7200000; // Sleep time changed to 2 hours
              gw.sleep(SLEEP_TIME);
            }
            else if((LightLevel > 5) && (nightSwitch) && ((!LEDSwitch) && (!SaverSwitch))){
              gw.send(msgLDR.set(LightLevel));
              SLEEP_TIME = 600000; // Sleep time changed to 10 minutes
            }
          }
        }
        else { //When night switch is off
          int LightLevel;
          for(int i = millis(); i < (millis() + 5000); i++){
            LightLevel = (100 - ((1023-analogRead(LDR_PIN))/10.23));
          }
          if(LightLevel < 20){
            gw.send(msgLDR.set(LightLevel));
            nightSwitch = true;
            SLEEP_TIME = 7200000; // Sleep time changed to 2 hours
            gw.sleep(INTERRUPT,FALLING, SLEEP_TIME);
          }
          else if((LightLevel < 30) && (!nightSwitch)){
            SLEEP_TIME = 600000; // Sleep time changed to 10 minutes
            gw.sleep(SLEEP_TIME);
          }
          else if((LightLevel < 50) && (!nightSwitch)){
            SLEEP_TIME = 1800000; // Sleep time changed to 30 minutes
            gw.sleep(SLEEP_TIME);
          }
        }
      }
      
      void pirswitch()
      {
        for(int i = millis(); i < (millis() + 5000); i++){ //Check PIR for activity 10 times with delay of half second
          boolean tripped = digitalRead(PIR_PIN) == HIGH;
          Serial.println(i);
          if(tripped){
            gw.send(msgPir.set(tripped?"1":"0"));
            Serial.println("Motion detected");
            //activity on function
            activityon();
            Serial.println("Loop terminated");
            break;
          }
        }
        delay(3000);
        activity = false;
      }
             
      void activityon()
      {
        //turn saver on
        digitalWrite(SAVER_PIN, LOW);
        SaverSwitch = true;
        Serial.println("Energy saver turned on");
        int LightLevel;
        for(int i = millis(); i < (millis() + 1000); i++){ //Check if energy saver is on
          LightLevel = (100 - ((1023-analogRead(LDR_PIN))/10.23));
        }
        if(LightLevel < 10){
          Serial.println("Light level is less than 50%, Turning LED on");
          digitalWrite(LED_PIN, LOW);
          LEDSwitch = true;
        }
        else{
          SLEEP_TIME = 1000;
          Serial.println("Sleep time changed to second");
        }
      }
        
      void activityoff()
      {
        delay(3000);
        //turn off saver or LED
        digitalWrite(SAVER_PIN, HIGH);
        digitalWrite(LED_PIN, HIGH);
        Serial.println("Activity finished");
        SaverSwitch = false;
        LEDSwitch = false;
        activity = false;
        SLEEP_TIME = 7200000;
        Serial.println("Sleep time changed to 2 hours");
      }
      
      posted in General Discussion
      vickey
      vickey
    • RE: Interrupt, Perform a specific function, not the loop

      I have tried it with single interrupt and It is working good so far on my mysensors 1.4 version. In case of interrupt

      wake = gw.sleep(INTERRUPT,FALLING, SLEEP_TIME);
      

      I use wake value (wake == 1) for function related to interrupt and use else condition for function related to timer wake up.

      posted in General Discussion
      vickey
      vickey

    Latest posts made by vickey

    • RE: Guide: Setting up and testing MQTT Client Gateway

      @hek I am using Stable ESP8266 version 2.0.0 from stable release

      posted in Development
      vickey
      vickey
    • RE: nodered "injected" between domoticz and mysensors

      @tbowmo May you please share your node-red set up by exporting your setup as flow? If feasible for you

      posted in Node-RED
      vickey
      vickey
    • RE: Guide: Setting up and testing MQTT Client Gateway

      I tried to make MQTT client gateway but it is giving following error while compiling

      C:\Users\Ahmed\AppData\Local\Temp\build8359488613260197686.tmp/arduino.ar(core_esp8266_postmortem.c.o): In function `abort':
      C:\Users\Ahmed\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0-rc2\cores\esp8266/core_esp8266_postmortem.c:177: multiple definition of `abort'
      GatewayESP8266MQTTClient.cpp.o:C:\Users\Ahmed\Documents\Arduino\libraries\MySensors/core/MyMainESP8266.cpp:46: first defined here
      collect2.exe: error: ld returned 1 exit status
      Error compiling.
      

      Any suggestions @hek ?

      posted in Development
      vickey
      vickey
    • RE: ESP8266 WiFi gateway port for MySensors

      Hi.
      I am having an issue with my ESP8266 gateway. I have tried all versions of mysensors including developmental versions, but my esp8266 does not show any serial debug, nor it gets connected to my router. I also enabled debug in configuration file. When I install AT firmware, it replies to AT command, it also works with nodemcu firmware, but it does not respond with Arduino firmware. May someone help me?

      posted in Development
      vickey
      vickey
    • RE: Openhab, Mosquitto, ESP-8266 12E wifi gateway

      And how did you configure domoticz? Did you use "Mysensors gateway with lan interface" type in hardware section or anything else? And may you send me the library files you used (I mean that complete zip which worked for you).

      posted in OpenHAB
      vickey
      vickey
    • RE: ESP8266 MySensors Gateway Crashes when Node Connects

      I am using mysensor 1.5.1 ESP8266 mysensor gateway. But It is not starting up. I am using 2A power supply. Here is the log.

      ESP8266 MySensors Gateway
      Connecting to Ahmed
      ............Connected!
      IP: 192.168.0.31
      
      ctx: cont 
      sp: 3ffebcb0 end: 3ffec010 offset: 01b0
      
      >>>stack>>>
      3ffebe60:  3ffea8af 000000ff 3ffea940 40205384  
      3ffebe70:  3ffea8af 00000030 3ffea940 402053d0  
      3ffebe80:  a8e1fc0a 000000a8 3ffea940 40205587  
      3ffebe90:  3ffea8af 0000000a 3ffea940 40204dd7  
      3ffebea0:  3fff1e58 4024371c 3fff235c 0000000a  
      3ffebeb0:  000000ff 3ffea8a8 3ffea8af 40203c7d  
      3ffebec0:  3ffec070 00000001 3ffebf2f 4020c5a8  
      3ffebed0:  402421c0 00000001 00000001 3ffec070  
      3ffebee0:  00000033 0000000a 3ffec070 4020b6e1  
      3ffebef0:  3ffebf2e 40243cbc 3fff1e58 0000000a  
      3ffebf00:  000000ff 00000000 0000000d 4020335e  
      3ffebf10:  40217e00 3ffead34 3ffe9390 3ffe93a4  
      3ffebf20:  00000065 3ffea940 3ffebf65 40203379  
      3ffebf30:  00000000 3ffea940 3ffea94a 0000000a  
      3ffebf40:  000000ff 00000000 3ffea8a8 40203f38  
      3ffebf50:  0000001d 3ffea8af 3ffea940 402053bc  
      3ffebf60:  3ffe92f8 a8e1fc0a 3ffea940 00000001  
      3ffebf70:  00000001 00000000 3ffea8a8 402040b0  
      3ffebf80:  00000001 0000000a 3ffea8a8 4020422b  
      3ffebf90:  00000000 0000000a 3ffea8a8 40204381  
      3ffebfa0:  0000007f 3ffec03c 40201cac 3ffeaff0  
      3ffebfb0:  40202320 00000001 0000000a 40201d4f  
      3ffebfc0:  1f00a8c0 00ffffff 0100a8c0 3ffec03c  
      3ffebfd0:  3ffe9328 3ffead34 3ffec070 402026ef  
      3ffebfe0:  3ffe98a8 1f00a8c0 00000000 00000000  
      3ffebff0:  3fffdc20 00000000 3ffec034 40201d1f  
      3ffec000:  00000000 00000000 3ffeaff0 40100398  
      <<<stack<<<
      
       ets Jan  8 2013,rst cause:1, boot mode:(3,7)
      
      load 0x4010f000, len 1264, room 16 
      tail 0
      chksum 0x42
      csum 0x42
      ~ld
      

      May someone help me?

      posted in Troubleshooting
      vickey
      vickey
    • RE: Openhab, Mosquitto, ESP-8266 12E wifi gateway

      This is what I have done already but failed.

      I get following error in my ESP-8266 Gateway debug

      ESP8266 MySensors Gateway
      Connecting to Ahmed
      .............Connected!
      IP: 192.168.0.31
      
      ctx: cont 
      sp: 3ffebcb0 end: 3ffec010 offset: 01b0
      
      >>>stack>>>
      3ffebe60:  3ffea8af 000000ff 3ffea940 40205384  
      3ffebe70:  3ffea8af 00000030 3ffea940 402053d0  
      3ffebe80:  a8e1fc0a 000000a8 3ffea940 40205587  
      3ffebe90:  3ffea8af 0000000a 3ffea940 40204dd7  
      3ffebea0:  0000001f ffffffff 40201c55 0000000a  
      3ffebeb0:  000000ff 3ffea8a8 3ffea8af 40203c7d  
      3ffebec0:  00000000 ffdfffff ffffffff 3fffc6fc  
      3ffebed0:  00000001 3ffeaff0 00000000 3fffdc20  
      3ffebee0:  3ffec03c 00000030 3ffec070 4020b6e1  
      3ffebef0:  3ffebf2e 40243cbc 3fff1e58 0000000a  
      3ffebf00:  000000ff 00000000 0000000d 4020335e  
      3ffebf10:  40217e00 3ffead34 3ffe9390 3ffe93a4  
      3ffebf20:  00000065 3ffea940 3ffebf65 40203379  
      3ffebf30:  00000000 3ffea940 3ffea94a 0000000a  
      3ffebf40:  000000ff 00000000 3ffea8a8 40203f38  
      3ffebf50:  0000001d 3ffea8af 3ffea940 402053bc  
      3ffebf60:  3ffe92f8 a8e1fc0a 3ffea940 00000001  
      3ffebf70:  00000001 00000000 3ffea8a8 402040b0  
      3ffebf80:  00000001 0000000a 3ffea8a8 4020422b  
      3ffebf90:  00000000 0000000a 3ffea8a8 40204381  
      3ffebfa0:  0000007f 3ffec03c 40201cac 3ffeaff0  
      3ffebfb0:  40202320 00000001 0000000a 40201d4f  
      3ffebfc0:  1f00a8c0 00ffffff 0100a8c0 3ffec03c  
      3ffebfd0:  3ffe9328 3ffead34 3ffec070 402026ef  
      3ffebfe0:  3ffe98a8 1f00a8c0 00000000 00000000  
      3ffebff0:  3fffdc20 00000000 3ffec034 40201d1f  
      3ffec000:  00000000 00000000 3ffeaff0 40100398  
      <<<stack<<<
      
       ets Jan  8 2013,rst cause:1, boot mode:(3,3)
      
      load 0x4010f000, len 1264, room 16 
      tail 0
      chksum 0x42
      csum 0x42
      ~ld
      
      posted in OpenHAB
      vickey
      vickey
    • RE: Openhab, Mosquitto, ESP-8266 12E wifi gateway

      @luisgcu I am also new to this kind of stuff. I tried Domoticz but failed to get my ESP8266 gateway working. May you share your setup? Did you use Mysensors library or lua scripts?

      posted in OpenHAB
      vickey
      vickey
    • RE: Interrupt, Perform a specific function, not the loop

      @AWI This code runs continuously for 5 seconds in order to get a stable reading of light using LDR, which is used to set night mode on and off.

      posted in General Discussion
      vickey
      vickey