Announcement

Collapse
No announcement yet.

Reading a switch from the API different than standard

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

    Reading a switch from the API different than standard

    I'm trying to convert all my NodeMCU boards from standard to API. I found something interesting and not sure if this is an user error (Most likely), something in the API or the board. I have attached the picture and the code. When I use the standard NodeMCU type, I have no issues, I connect 3 of these sensors on Pin 16 (D0) Pin 5 (D1) and Pin 4 (D2). When I instead use the API, some pins work and some pin do not. In few cases, as an example when I plug it in D0 the red light on the NodeMCU comes up while On D3 (Not sure if this is the right pin, may be D2) when the sensor is close, I have a blue light on the board and when is open I have no light. What am I doing wrong?

    Thanks,
    Aldo

    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) {'
    Attached Files

    #2
    try changing

    pinMode(sensorPin, INPUT);

    to

    pinMode(sensorPin, INPUT_PULLUP);

    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, that did it.

      Aldo

      Comment

      Working...
      X