Navigation

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

    Best posts made by Graham

    • RE: ESP8266gateway with sensor

      Here is my code for doing something equivalent. You seem to have the pinMode line missing in setup()

      // Initialize motion message
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup() { 
        pinMode(MOTION_SENSOR_PIN, INPUT_PULLUP);      // sets the motion sensor digital pin as input
      }
      
      void presentation() {
        // Present locally attached sensors here    
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Motion Sensor", "1.1");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_MOTION);
      }
      
      boolean pinstate = false;
      
      void loop() {
        boolean newstate = (digitalRead(MOTION_SENSOR_PIN) == HIGH);
        if (newstate != pinstate) {
          if (newstate == true) {
            send(msg.set("1"));
            Serial.println("Motion Started");
            pinstate = newstate;
          } else {
            send(msg.set("0"));
            Serial.println("Motion Stopped");
            pinstate = newstate;
          }
        }
      }
      
      posted in Hardware
      Graham
      Graham