Announcement

Collapse
No announcement yet.

Two NodeMCU, one disconnects the other

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Two NodeMCU, one disconnects the other

    I have two NodeMCU, one using the normal NodeMcu and an analog sensor, the other is identical to the above but I try to use the NodeMCU API (Code below) When I connect the one with API, it disconnects the normal NodeMcu, any reason why?




    Code:
    //**************Declare your variables here******************* 
    
    int sensorPin  = 4;     //  ESP 12E pin D2
    int sensorValue = 0;  // variable to store the value coming from the sensor
    
    //****************************************************************
     
    void HSSetup() {
      
      //************************
      //Add YOUR SETUP HERE;
      //************************
    
    pinMode(sensorPin, INPUT);
    
    }
    
    void HSloop() {
        //************************
        //Add YOUR CODE HERE;
        //************************
        /*Execute regardless of connection status*/
    
     if (IsConnected == true) {
       /*Execute ONLY when HomeSeer is connected*/
       // read the input on analog pin 4:
       // analog reading (which goes from 0 - 1023)
      
        sensorValue = analogRead(sensorPin);
        SendToHS(1,sensorValue);
     }   
     }    // end of 'if (IsConnected == true) {'

    #2
    The problem is your API code. You are sending the value on every loop of the code so this will be flooding the plugin with data. You need to add code that checks if the Analog pin has changed value and if so send it to homeseer.

    something like this is fine for a analog device that is not changing value to often but if you have a device that is always changing then it is best to add a timer to send the data every x seconds.

    Code:
    //**************Declare your variables here******************* 
    
    int sensorPin  = 4;     //  ESP 12E pin D2
    int sensorValue = 0;  // variable to store the value coming from the sensor
    
    //****************************************************************
     
    void HSSetup() {
      
      //************************
      //Add YOUR SETUP HERE;
      //************************
    
    pinMode(sensorPin, INPUT);
    
    }
    
    void HSloop() {
        //************************
        //Add YOUR CODE HERE;
        //************************
        /*Execute regardless of connection status*/
    
     if (IsConnected == true) {
       /*Execute ONLY when HomeSeer is connected*/
       // read the input on analog pin 4:
       // analog reading (which goes from 0 - 1023)
    
      if (analogRead(sensorPin) <> sensorValue){
        sensorValue = analogRead(sensorPin);
        SendToHS(1,sensorValue);
     }   
     }
     }    // end of 'if (IsConnected == true) {'
    Greig.
    Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


      #3
      Thanks Greig for all your help,
      Aldo

      Comment


        #4
        I'm getting this message, Arduino: 1.8.1 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"

        E:\Aldo\Downloads\APIBoard4\APIBoard4.ino: In function 'void HSloop()':

        APIBoard4:38: error: expected primary-expression before '>' token

        if (analogRead(sensorPin) <> sensorValue) {

        ^

        exit status 1
        expected primary-expression before '>' token

        This report would have more information with
        "Show verbose output during compilation"
        option enabled in File -> Preferences.

        I think it does not like the <>. When I changed it to == it compiled fine.

        //**************Declare your variables here*******************

        int sensorPin = 4; // ESP 12E pin D2
        int sensorValue = 0; // variable to store the value coming from the sensor

        //************************************************************ ****

        void HSSetup() {

        //************************
        //Add YOUR SETUP HERE;
        //************************

        pinMode(sensorPin, INPUT);

        }

        void HSloop() {
        //************************
        //Add YOUR CODE HERE;
        //************************
        /*Execute regardless of connection status*/

        if (IsConnected == true) {
        /*Execute ONLY when HomeSeer is connected*/
        // read the input on analog pin 4:
        // analog reading (which goes from 0 - 1023)

        if (analogRead(sensorPin) <> sensorValue) {
        sensorValue = analogRead(sensorPin);

        SendToHS(1,sensorValue);
        }
        }
        } // end of 'if (IsConnected == true) {'

        Comment


          #5
          Sorry but I am used to coding in other languages.

          Change:
          if (analogRead(sensorPin) <> sensorValue) {
          to
          if (analogRead(sensorPin) != sensorValue) {

          Greig.
          Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
          X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
          Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
          Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
          Scripts =
          Various

          Comment


            #6
            Not a problem, I googled it and I saw it as well.

            Unfortunately now I do not get open or close but random values and then it stops sending them to the plugin. I know the pins are correct because I use them on a different board, I'm I reading it incorrectly? this sensor should be on or off.

            Comment


              #7
              What sensor is connected to the Analog pin?

              Greig.
              Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
              X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
              Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
              Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
              Scripts =
              Various

              Comment


                #8
                This one

                ZP4510 Liquid Water Level Sensor Vertical Float Switches
                https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1
                Attached Files

                Comment


                  #9
                  Originally posted by aldo View Post
                  This one

                  ZP4510 Liquid Water Level Sensor Vertical Float Switches
                  https://www.amazon.com/gp/product/B0...?ie=UTF8&psc=1
                  Ok I think this is just a switch and not an analog device so you need "digitalRead"

                  Try this
                  Code:
                  //**************Declare your variables here*******************
                  
                  int sensorPin  = 4;     //  ESP 12E pin D2
                  int sensorValue = 0;  // variable to store the value coming from the sensor
                  
                  //****************************************************************
                  
                  void HSSetup() {
                  
                    //************************
                    //Add YOUR SETUP HERE;
                    //************************
                  
                    pinMode(sensorPin, INPUT);
                  
                  }
                  
                  void HSloop() {
                    //************************
                    //Add YOUR CODE HERE;
                    //************************
                    /*Execute regardless of connection status*/
                  
                    if (IsConnected == true) {
                      /*Execute ONLY when HomeSeer is connected*/
                  
                      // read the input pin and compare to the last state
                      if (digitalRead(sensorPin) != sensorValue) {
                        sensorValue = digitalRead(sensorPin);
                        SendToHS(1, sensorValue);
                      }
                    }
                  }    // end of 'if (IsConnected == true) {'
                  Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
                  X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
                  Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
                  Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
                  Scripts =
                  Various

                  Comment


                    #10
                    You are fantastic, thank you.

                    Comment

                    Working...
                    X