Announcement

Collapse
No announcement yet.

NodeMcu - Servo and OneWire?

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

    NodeMcu - Servo and OneWire?

    Just bought the plugin and loving it! But, I really need to use wireless.

    Are there plans to add servo and One Wire support for NodeMcu?

    If not, has anybody managed to get NodeMcu working with some version of these?

    #2
    I have a NodeMCU working with OneWire.

    I bought two to test with, one on the board and the other one to use in the field. We are using one now to monitor my gas water heater. This unit has 4 OneWire temperature sensors hanging off the NodeMCU. One temp sensor for each water line (hot and cold), the other two sensors monitor temperature from the top and bottom of the unit. The unit also has a LED on it that I flash off an on so it is a visual indication that it working. I have not had any issue with the unit since it was deployed for testing. The unit uses the plugin API to function. If you are interested, I could provide some screenshots and the Arduino code.
    Billy

    Comment


      #3
      Originally posted by bdraper View Post
      I have a NodeMCU working with OneWire.

      I bought two to test with, one on the board and the other one to use in the field. We are using one now to monitor my gas water heater. This unit has 4 OneWire temperature sensors hanging off the NodeMCU. One temp sensor for each water line (hot and cold), the other two sensors monitor temperature from the top and bottom of the unit. The unit also has a LED on it that I flash off an on so it is a visual indication that it working. I have not had any issue with the unit since it was deployed for testing. The unit uses the plugin API to function. If you are interested, I could provide some screenshots and the Arduino code.
      I'd really appreciate it if you could post the code and screenshots. It would give ne a good leg-up on the project. Thanks!

      Comment


        #4
        Sure no problem, let me know if you have any questions.

        This is a screenshot of the devices.
        Click image for larger version

Name:	arduino2.jpg
Views:	1
Size:	33.5 KB
ID:	1194274

        This is a screenshot of the plugin setup.

        Click image for larger version

Name:	arduino1.JPG
Views:	1
Size:	71.5 KB
ID:	1194273


        This is the sketch, I changed the SSI, password field and removed the IP addresses.

        Code:
        /*************************************************************
         *Arduino to Homeseer 3 Plugin API written by Enigma Theatre.*
         * V1.0.0.140                                                *
         *                                                           *
         *************************************************************/
        int FromHS[50];                                              
        boolean IsConnected = false;                                 
        //************************************************************
        
        
        //**************Declare your variables here******************* 
        
        #include <OneWire.h>
        #include <DallasTemperature.h>
        
        /********************************************************************/
        // Data wire is plugged into a pin on the Arduino
        #define v_one_wire_bus_5 5    // NodeMCU D1 the number of the pin
        #define v_one_wire_bus_2 2    // NodeMCU D4 the number of the pin
        #define v_one_wire_bus_14 14  // NodeMCU D5 the number of the pin
        #define v_one_wire_bus_12 12  // NodeMCU D6 the number of the pin
        
        /********************************************************************/
        // Setup a oneWire instance to communicate with any OneWire devices  
        // (not just Maxim/Dallas temperature ICs) 
        OneWire oneWire_5(v_one_wire_bus_5);
        OneWire oneWire_2(v_one_wire_bus_2);
        OneWire oneWire_14(v_one_wire_bus_14);
        OneWire oneWire_12(v_one_wire_bus_12);
        
        /********************************************************************/
        // Pass our oneWire reference to Dallas Temperature. 
        DallasTemperature v_sensors_5(&oneWire_5);
        DallasTemperature v_sensors_2(&oneWire_2);
        DallasTemperature v_sensors_14(&oneWire_14);
        DallasTemperature v_sensors_12(&oneWire_12);
        
        float v_current_fahrenheit_5 = 0;
        float v_current_fahrenheit_2 = 0;
        float v_current_fahrenheit_14 = 0;
        float v_current_fahrenheit_12 = 0;
        
        float v_last_fahrenheit_5 = 0;
        float v_last_fahrenheit_2 = 0;
        float v_last_fahrenheit_14 = 0;
        float v_last_fahrenheit_12 = 0;
        
        // constants won't change. Used here to set a pin number:
        const int v_ledPin_13 =  13;            // NodeMCU D7 the number of the pin
        int v_ledState_13 = LOW;                // v_ledState used to set the LED
        int v_ledValue_13 = 0;                  // v_ledValue used to send to HomeSeer
        
        // constants won't change. Used here to set a pin number:
        const int v_ledPin_15 =  15;            // NodeMCU D8 the number of the pin
        int v_ledState_15 = LOW;                // v_ledState used to set the LED
        int v_ledValue_15 = 0;                  // v_ledValue recieved from HomeSeer
        
        // Generally, you should use "unsigned long" for variables that hold time
        // The value will quickly become too large for an int to store
        unsigned long previousMillis = 0;       // will store last time LED was updated
        
        // constants do not change:
        const long interval = 5000;             // interval at which to blink (milliseconds) 5 seconds
        
        /********************************************************************/ 
        
        
        //****************************************************************
        
        
        void HSSetup() {
          
          //************************
          //Add YOUR SETUP HERE;
          //************************
        
          pinMode(v_ledPin_13, OUTPUT); // set the digital pin as output:
          pinMode(v_ledPin_15, OUTPUT); // set the digital pin as output:
        
          // start serial port
          Serial.begin(9600);
          Serial.println("Temperature Display");
        
          // Start up the library
          v_sensors_5.begin();
          v_sensors_2.begin();
          v_sensors_14.begin();
          v_sensors_12.begin();
        }
        
        void HSloop() {
                       
            //************************
            //Add YOUR CODE HERE;
            //************************
            /* To Send Data to Homeseer use SendToHS(Device,Value)
             Eg.. SendToHS(1,200); where 1 is the API device in homeseer and 200 is the value to send
             To Recieve data from Homeseer look up the FromHS array that is updated when the device value changes.
             Eg.. FromHS[5] would be the data from API Output device 5
             All code that is located just below this block will execute regardless of connection status!
             You can include SendToHS() calls, however when there isn't an active connection, it will just return and continue.
             If you only want code to execute when HomeSeer is connected, put it inside the if statement below.
             */
        
            /*Execute regardless of connection status*/
        
         if (IsConnected == true) {
           /*Execute ONLY when HomeSeer is connected*/
        
           Serial.print("LED is: " );     
           Serial.println(FromHS[0]); 
        
           v_ledValue_15 = FromHS[0];
        
           // Find value of LED:
           if (v_ledValue_15 == 255) {
             v_ledState_15 = HIGH;
           } else {
             v_ledState_15 = LOW;
           }
           digitalWrite(v_ledPin_15, v_ledState_15);   // set the LED with the ledState of the variable:
        
           // check to see if it's time to blink the LED; that is, if the difference
           // between the current time and last time you blinked the LED is bigger than
           // the interval at which you want to blink the LED.
           unsigned long currentMillis = millis();
        
           if (currentMillis - previousMillis >= interval) {
             // save the last time you blinked the LED
             previousMillis = currentMillis;
        
             // if the LED is off turn it on and vice-versa:
             if (v_ledState_13 == LOW) {
               v_ledState_13 = HIGH;
               v_ledValue_13 = 100;
             } else {
               v_ledState_13 = LOW;
               v_ledValue_13 = 0;
             }
             digitalWrite(v_ledPin_13, v_ledState_13);   // set the LED with the ledState of the variable:
             SendToHS(5,v_ledValue_13);
             
             v_sensors_5.requestTemperatures(); // Send the command to get temperature readings
             v_sensors_2.requestTemperatures(); // Send the command to get temperature readings
             v_sensors_14.requestTemperatures(); // Send the command to get temperature readings
             v_sensors_12.requestTemperatures(); // Send the command to get temperature readings
             /********************************************************************/
             v_current_fahrenheit_5 = v_sensors_5.getTempCByIndex(0)* 1.8 + 32.0;
             v_current_fahrenheit_2 = v_sensors_2.getTempCByIndex(0)* 1.8 + 32.0;
             v_current_fahrenheit_14 = v_sensors_14.getTempCByIndex(0)* 1.8 + 32.0;
             v_current_fahrenheit_12 = v_sensors_12.getTempCByIndex(0)* 1.8 + 32.0;
        
             if (v_current_fahrenheit_5 != v_last_fahrenheit_5){
                Serial.print("Temperature 5 is: ");
                Serial.println(v_current_fahrenheit_5); 
                SendToHS(1,v_current_fahrenheit_5);
                v_last_fahrenheit_5 = v_current_fahrenheit_5;
              }
             if (v_current_fahrenheit_2 != v_last_fahrenheit_2){
                Serial.print("Temperature 2 is: ");
                Serial.println(v_current_fahrenheit_2); 
                SendToHS(2,v_current_fahrenheit_2);
                v_last_fahrenheit_2 = v_current_fahrenheit_2;
              }
             if (v_current_fahrenheit_14 != v_last_fahrenheit_14){
                Serial.print("Temperature 14 is: ");
                Serial.println(v_current_fahrenheit_14); 
                SendToHS(3,v_current_fahrenheit_14);
                v_last_fahrenheit_14 = v_current_fahrenheit_14;
              }      
             if (v_current_fahrenheit_12 != v_last_fahrenheit_12){
                Serial.print("Temperature 12 is: ");
                Serial.println(v_current_fahrenheit_12); 
                SendToHS(4,v_current_fahrenheit_12);
                v_last_fahrenheit_12 = v_current_fahrenheit_12;
              }      
            }
          }
        }
        
        
        //************Do not change anything after Here*****************
         
        #define ISIP 1
        #define BoardType 3
        const byte BoardAdd = 5;
        
        #include <EEPROM.h>
        
        #if BoardType == 3
        #include <ESP8266WiFi.h>
        #include <WiFiUdp.h>
        char ssid[] = "SSID";
        char pass[] = "PASS";
        #else
        #include <SPI.h>
        #include <Ethernet.h>
        #include <EthernetUdp.h>
        #endif
        
        
        #if ISIP == 1
        
        
        byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x05};
        IPAddress ip(123,123,123,123);     //IP entered In HS config.
        const unsigned int localPort = 1234;      //port entered In HS config.
        IPAddress HomeseerIP(123,123,123,123); //Homeseer IP address
        IPAddress ServerIP(EEPROM.read(2),EEPROM.read(3),EEPROM.read(4),EEPROM.read(5));
        IPAddress gateway(123,123,123,123);
        IPAddress subnet(255,255,255,0);
        byte EEpromVersion = EEPROM.read(250);
        char packetBuffer[UDP_TX_PACKET_MAX_SIZE];              
        const unsigned int ServerPort = 8888; 
        #endif
        
                                                
                                   
        
        #if BoardType == 3
        WiFiUDP Udp;
        WiFiUDP SendPort;
        #else
        EthernetUDP Udp;
        #endif
        
        #if BoardType == 3
        void resetFunc() {
          ESP.restart();
        }
        #else
        void(* resetFunc) (void) = 0;
        #endif
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        char* Version = "API1.0.0.140";
        
        byte Byte1, Byte2, Byte3;
        unsigned int Byte4, Byte5;
        
        
        void setup() {
        
        #if BoardType == 3
         // WiFi.persistent(false);
          EEPROM.begin(256);
          EEpromVersion = EEPROM.read(250);
        #endif
        
        #if ISIP == 1
            if (EEpromVersion!=22) {
            ServerIP=HomeseerIP;
            EEPROM.write(2,ServerIP[0]);
            EEPROM.write(3,ServerIP[1]);
            EEPROM.write(4,ServerIP[2]);
            EEPROM.write(5,ServerIP[3]);
            EEPROM.write(250,22); //Store the version where the eeprom data layout was last changed
            EEpromVersion=22;
          }
        #if BoardType == 3
          //Serial.begin(115200);
          WiFi.begin(ssid, pass);
          WiFi.config(ip, gateway, subnet);
        
          while (WiFi.status() != WL_CONNECTED) {
            delay(500);
          }
        #else
          Ethernet.begin(mac, ip, gateway, gateway, subnet);
        #endif
          Udp.begin(localPort);
          Udp.setTimeout(0);
          delay(1000);
        SendConnect();
        #else
          Serial.begin(115200);
          Serial.flush();
          Serial.setTimeout(0);
          delay(1000);
          Serial.print("Connect ");
          Serial.println(BoardAdd);
        #endif
        
          IsConnected = false;
        HSSetup();
        }
        
        
        void loop(){
          HSloop();
        #if ISIP == 1
          UDPCheck();
        #endif
        }
        
        
        void SendConnect()
        {
        #if ISIP == 0
          Serial.print("Connect ");
          Serial.println(BoardAdd);
        #else
            Udp.beginPacket(HomeseerIP,ServerPort);  //First send a connect packet to the dynamic IP stored in eeprom
            Udp.print("Connect ");
            Udp.print(BoardAdd);
            Udp.endPacket();
            if (ServerIP!=HomeseerIP) {
              Udp.beginPacket(HomeseerIP,ServerPort);  //Then if the stored value doesn't match the pre-specified one, send a connect packet there also
              Udp.print("Connect ");
              Udp.print(BoardAdd);
              Udp.endPacket();
            }
         
        #endif
        }
        
        
        
        #if ISIP == 1
        void UDPCheck(){
          int packetSize = Udp.parsePacket();
          if(packetSize)
          {
            
         #if BoardType == 3
            IPAddress remote = Udp.remoteIP();
            Byte1 = Udp.parseInt();
            Udp.read();
            Byte2 = Udp.read();
            Udp.read();
            Byte3 = Udp.parseInt();
            Udp.read();
            Byte4 = Udp.parseInt();
            Udp.read();
            Byte5 = Udp.parseInt();
            DataEvent();
            #else
        
           ServerIP = Udp.remoteIP();
            Byte1 = Udp.parseInt();
            Udp.read();
            Byte2 = Udp.read();
            Byte3 = Udp.parseInt();;
            Byte4 = Udp.parseInt();
            Byte5 = Udp.parseInt();;
        
            DataEvent();
        #endif
          }
        }
        
        #else
        void serialEvent() {
          while (Serial.available() > 0) {
            delay(17);
        
        
            Byte1 = Serial.parseInt();
            Serial.read();  
            Byte2 = Serial.read(); 
            Byte3 = Serial.parseInt();
            Byte4 = Serial.parseInt();
            Byte5 = Serial.parseInt();
            DataEvent();
          }
        }
        #endif
        
        
        /*
        
        Used Data Input Cases
        D Disconnect
        r reset
        K Keepalive
        O PinMode Output Set
        d Input debounce time set
        C Connect request
        c Connection established - report current status
        */
        void DataEvent() {
        
          if (Byte1 == BoardAdd) {
        
        #if ISIP == 1
              if (Udp.remoteIP() != ServerIP) {
                ServerIP=Udp.remoteIP();
                EEPROM.write(2,ServerIP[0]);
                EEPROM.write(3,ServerIP[1]);
                EEPROM.write(4,ServerIP[2]);
                EEPROM.write(5,ServerIP[3]);
              }     
        #endif
        
            switch (Byte2) {
            case 'c':
              IsConnected = true;
              break;
        
            case 'C':   
        #if ISIP == 1
              Udp.beginPacket(HomeseerIP, ServerPort);
              Udp.print("Version ");
              Udp.print(BoardAdd);
              Udp.print(" ");
              Udp.print(Version);
              Udp.println(" HS3");
              Udp.endPacket();
        
              Udp.beginPacket(HomeseerIP, ServerPort);
              delay(100);
              Udp.print("Connected ");
              Udp.println(BoardAdd);
              Udp.endPacket();
        #else
              Serial.print("Version ");
              Serial.print(BoardAdd);
              Serial.print(" ");
              Serial.print(Version);
              Serial.println(" HS3"); 
              delay(100);
              Serial.print("Connected ");
              Serial.println(BoardAdd);
        #endif
              delay(100);
              IsConnected = false;
              break;
        
            case 'K':
              delay(200);
        #if ISIP == 1
              Udp.beginPacket(HomeseerIP, ServerPort);
              Udp.print("Alive ");
              Udp.println(BoardAdd);
              Udp.endPacket();
              if (Udp.remoteIP() != ServerIP) {
                ServerIP=Udp.remoteIP();
                EEPROM.write(2,ServerIP[0]);
                EEPROM.write(3,ServerIP[1]);
                EEPROM.write(4,ServerIP[2]);
                EEPROM.write(5,ServerIP[3]);
              }     
        #else     
              Serial.print("Alive ");
              Serial.println(BoardAdd);
        #endif
              break; 
              
              case 'r':
              delay(200);
              resetFunc();  //call reset
              break; 
        
            case 'O':
              FromHS[Byte3] = Byte4;
              break; 
        
            case 'D':
              IsConnected = false;
              break;   
            }
          }
        }
        
        void SendToHS(byte Device, long Data){
        if (IsConnected == true) {
        #if ISIP == 1
          Udp.beginPacket(HomeseerIP, ServerPort);
          Udp.print(BoardAdd);
          Udp.print(" API ");
          Udp.print(Device);
          Udp.print(" ");
          Udp.print(Data);
          Udp.endPacket();
        #else
          Serial.print(BoardAdd);
          Serial.print(" API ");
          Serial.print(Device);
          Serial.print(" ");
          Serial.println(Data);
        #endif
        }
        }
        
        void SendToHS(byte Device, int Data){
        if (IsConnected == true) {
        #if ISIP == 1
          Udp.beginPacket(HomeseerIP, ServerPort);
          Udp.print(BoardAdd);
          Udp.print(" API ");
          Udp.print(Device);
          Udp.print(" ");
          Udp.print(Data);
          Udp.endPacket();
        #else
          Serial.print(BoardAdd);
          Serial.print(" API ");
          Serial.print(Device);
          Serial.print(" ");
          Serial.println(Data);
        #endif
        }
        }
        
        void SendToHS(byte Device, float Data){
        if (IsConnected == true) {
        #if ISIP == 1
          Udp.beginPacket(HomeseerIP, ServerPort);
          Udp.print(BoardAdd);
          Udp.print(" API ");
          Udp.print(Device);
          Udp.print(" ");
          Udp.print(Data);
          Udp.endPacket();
        #else
          Serial.print(BoardAdd);
          Serial.print(" API ");
          Serial.print(Device);
          Serial.print(" ");
          Serial.println(Data);
        #endif
        }
        }
        
        void SendToHS(byte Device, double Data){
        if (IsConnected == true) {
        #if ISIP == 1
          Udp.beginPacket(HomeseerIP, ServerPort);
          Udp.print(BoardAdd);
          Udp.print(" API ");
          Udp.print(Device);
          Udp.print(" ");
          Udp.print(Data);
          Udp.endPacket();
        #else
          Serial.print(BoardAdd);
          Serial.print(" API ");
          Serial.print(Device);
          Serial.print(" ");
          Serial.println(Data);
        #endif
        }
        }
        Billy

        Comment


          #5
          Originally posted by bdraper View Post
          Sure no problem, let me know if you have any questions.
          Really helpful. Your example cleared things up. Thanks so much.

          Comment


            #6
            Anytime, glad to help.
            Billy

            Comment


              #7
              Originally posted by bdraper View Post
              Anytime, glad to help.
              bdraper,
              Would you mind posting some pictures of the hardware side of your setup?
              Are you connecting the NodeMCU to an Arduino board or using it as an Arduino board?
              Sorry for the newbie question. I'm just getting back into this world and dusting off my old Arduino boards and home automation setup. Only bumped into NodeMCU today.
              What temperature sensors did you use and are they holding up fine?
              How did you thermally couple them to the pipes and water heater?
              Thanks for sharing.

              Comment


                #8
                Originally posted by thestosh View Post
                bdraper,
                Would you mind posting some pictures of the hardware side of your setup?
                Are you connecting the NodeMCU to an Arduino board or using it as an Arduino board?
                Sorry for the newbie question. I'm just getting back into this world and dusting off my old Arduino boards and home automation setup. Only bumped into NodeMCU today.
                What temperature sensors did you use and are they holding up fine?
                How did you thermally couple them to the pipes and water heater?
                Thanks for sharing.
                Sure, no problem. These are pictures of the NodeMCU unit on our water heater. I have the breadboard and NodeMCU in a clear tupperware container with holes for the probes, but took it out for the picture. Also included is a picture of the temperature probe connected to the hot water line. I usually put a dab of CPU grease but have not been able to tell much of a difference without it. In this instance, the probe is connected with a metal hose clamp (hot water line). I have connected these probes to things with zip ties... In this instance, the probe connected to the cold water line is attached with a couple of zip ties.

                NodeMCU out of the container
                Click image for larger version

Name:	NodeMCU.jpg
Views:	1
Size:	60.0 KB
ID:	1196127

                Probe connected to hot water line
                Click image for larger version

Name:	temp_waterline.jpg
Views:	1
Size:	38.3 KB
ID:	1196126

                Hope this helps.
                Billy

                Comment


                  #9
                  Thanks so much for the hardware pics. A picture is worth a thousand words, right?

                  Comment


                    #10
                    Originally posted by thestosh View Post
                    Thanks so much for the hardware pics. A picture is worth a thousand words, right?
                    Not a problem, I agree, a picture is worth a thousand words.
                    Billy

                    Comment

                    Working...
                    X