Announcement

Collapse
No announcement yet.

99% there just a syntax error?

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

  • 99% there just a syntax error?

    Hi,

    I am new to the Arduino world...and enjoying it, have a few questions for the plugin.

    I have an UNO with the open aquarium and aquaponics kit (the open aquarium goes on top of the UNO and the aquaponics on top of the open aquarium link here:
    https://www.cooking-hacks.com/docume...arduino/#img_3

    with the sketch provided for the open aquarium and aquaponics I can read pH and EC conductivity and would like to see these values in HSTouch for a screen I have created.

    Do I need to use the API version of the plugin or should I use the normal Type?

    Or should I open the "Normal" .ino file and add my code for reading the pH and EC?

    It appears I must use the API and send my values to a Homeseer device using SendToHS(Device,Value)...

    Just wanted to confirm since I am a super duper novice with Arduino.

    Thanks
    Chris
    Last edited by clafa; May 29th, 2017, 09:03 AM.

  • #2
    Yes you have the correct idea as you will need to use the API.ino and send the values.

    Sent from my SM-G925F using Tapatalk
    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
      OK Almost there...99%

      Hi,

      Feel like I am 99% there but I am facing an issue, and need a little guidance:

      I was able to successfully perform the following:
      Installed latest Beta version 1.0.0.142
      Purchase the Plugin!

      Installed the Arduino IDE ver 1.8.1
      Downloaded the Arduino libraries from the plugin
      Downloaded and installed the libraries for the Aquaphonics

      Added the UNO board to the plugin using COM Port 4
      Type: Arduino API
      Was able to Connect HS3 with the Board!

      Downloaded the ino file for the API.

      Added my libraries, variables and setup functions, and loop.

      I seem to have a rookie error on the IF statement of:
      /*Execute regardless of connection status*/

      I have pasted the Ino file in Word to this reply.

      THANKS for your help,
      Chris
      Attached Files
      Last edited by clafa; May 29th, 2017, 08:53 AM. Reason: removing old errors

      Comment


      • #4
        There are a couple of changes in the code below. Try it and see if it helps.

        Code:
        #include <OpenAquarium.h>
        #include <RTClib.h>
        
        /*************************************************************
          Arduino to Homeseer 3 Plugin API written by Enigma Theatre.
           V1.0.0.140
         *                                                           *
         *************************************************************/
           //CPLT indicates code inserts by Chris
          int FromHS[50];
          boolean IsConnected = false;
          //************************************************************
          //CPLT - below the calibration of pH and EC
        
           #define point_1_cond 12880   // Write here your EC calibration value of the solution 1 in S/cm
           #define point_1_cal 140      // Write here your EC value measured in resistance with solution 1
           #define point_2_cond 1413    // Write here your EC calibration value of the solution 2 in S/cm
           #define point_2_cal 668      // Write here your EC value measured in resistance with solution 2
        
           #define calibration_point_4 2207  //Write here your measured value in mV of pH 4
           #define calibration_point_7 2104  //Write here your measured value in mV of pH 7
           #define calibration_point_10 1987 //Write here your measured value in mV of pH 10
          //CPLT
          //**************Declare your variables here*******************
          //CPLT - These variables will be the HS3 devices that send info to UNO, hardcoded for now
           int buttonState = 0;
           int Estado =0;
          //CPLT
          //****************************************************************
        
          void HSSetup() {
        
          //************************
          //Add YOUR SETUP HERE;
          //CPLT
            Serial.begin(115200);  //this is to see in the serial the pH and EC values
            OpenAquarium.init();
            OpenAquarium.calibrateEC(point_1_cond, point_1_cal, point_2_cond, point_2_cal);
            OpenAquarium.calibratepH(calibration_point_4, calibration_point_7, calibration_point_10);
          //CPLT
          //************************
        
          }
        
          void HSloop() {
          //CPLT
            buttonState = HIGH; // Hardcoding value for now, will read it later from Homeseer device
        
          if (buttonState == HIGH) {
            Serial.println ("buttonState is High");
            float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
            Serial.print(F("EC Value in resistance = "));
            Serial.print(resistanceEC);
        
            Serial.print(F(" // EC Value = "));
            float EC = OpenAquarium.ECConversion(resistanceEC); //EC Value in S/cm
            Serial.print(EC);
            Serial.println(F(" uS/cm"));
        
            int mvpH = OpenAquarium.readpH(); //Value in mV of pH
            Serial.print(F("pH Value in mV = "));
            Serial.print(mvpH);
        
            Serial.print(F(" // pH = "));
            float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
            Serial.println(pH);
            
          } else {
        
                Serial.println ("buttonSate is Low"); //For now this code will not run since buttonState = High is hardcoded
              }
        
        
        
            //************************
            //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*/
        // SendToHS (1,mvpH); later want to send the value of ph to Homeseer device ID 535
        //############SendToHS takes the API input number not the device ref#################
        
        
        // if (IsConnected == true) {
          /*Execute ONLY when HomeSeer is connected*/
          
        }
        
        //}##############I dont think this is required##################
        
        
        
        //************Do not change anything after Here*****************
        
        #define ISIP 0
        #define BoardType 1
        const byte BoardAdd = 1;
        
        #include <EEPROM.h>
        
        #if BoardType == 3
        #include <ESP8266WiFi.h>
        #include <WiFiUdp.h>
        char ssid[] = "TALKTALK-C94ECC";
        char pass[] = "YNH9EXWA";
        #else
        #include <SPI.h>
        #include <Ethernet.h>
        #include <EthernetUdp.h>
        #endif
        
        
        #if ISIP == 1
        
        
        byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01};
        IPAddress ip(10, 0, 0, 152);  //IP entered In HS config.
        const unsigned int localPort = 8900;      //port entered In HS config.
        IPAddress HomeseerIP(10, 0, 0, 151); //Homeseer IP address
        IPAddress ServerIP(EEPROM.read(2), EEPROM.read(3), EEPROM.read(4), EEPROM.read(5));
        IPAddress gateway(192, 168, 0, 1);
        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
          }
        }
        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


        • #5
          Updating devices error

          Hi,

          I updated the .ino file and now I can compile and connect to the board.
          I can see information being sent to Homeseer but the status, the value or anything on the input devices is not being updated.

          I have 2 API Input devices, I have tried set them up as string, value and Value and String but these devices don't get updated.

          I am using Arduino ver 1.0.0.142.
          My .ino file is attached and the arduino log.

          Thanks for your help,
          Chris
          Attached Files

          Comment


          • #6
            Originally posted by clafa View Post
            Hi,

            I updated the .ino file and now I can compile and connect to the board.
            I can see information being sent to Homeseer but the status, the value or anything on the input devices is not being updated.

            I have 2 API Input devices, I have tried set them up as string, value and Value and String but these devices don't get updated.

            I am using Arduino ver 1.0.0.142.
            My .ino file is attached and the arduino log.

            Thanks for your help,
            Chris
            you need to comment out the code as follows as you can not use the serial port as this is what the board is using to connect to HS and sending other data will not work.


            Code:
            //  Serial.begin(115200);
            Code:
              //Add YOUR CODE HERE;
            //CPLT INSERTS STARTS HERE
            //  float resistanceEC = OpenAquarium.readResistanceEC(); // EC Value in resistance
            //  Serial.print(F("EC Value in resistance = ")); 
            //  Serial.print(resistanceEC);
            //
            //  Serial.print(F(" // EC Value = "));
            //  float EC= OpenAquarium.ECConversion(resistanceEC); //EC Value in S/cm
            //  Serial.print(EC);
            //  Serial.println(F(" S/cm"));
            //
            //  int mvpH = OpenAquarium.readpH();  //Value in mv of pH
            //  Serial.print(F("pH Value in mV = "));
            //  Serial.print(mvpH);
            //
            //  Serial.print(F(" // pH = "));
            //  float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
            // // Serial.println(pH);
             // float ppH = OpenAquarium.pHConversion(mvpH);
            I also can not see that the board is connected in HS log so comment the lines out then try to connect with logging on and see what you get.

            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


            • #7
              Commented code and log showing live connection

              Hi Greig,

              I commented out all the code with "serial" and activated the log and then connected the board.
              The board connects on COM 4 and I only see "alive pin" which I assume its something to make sure the board is connected, but the devices still have no values, strings or any updates.

              I am also pasting a screenshot of 1 device which shows no value or string.

              Thanks again for all your help.

              Chris
              Attached Files

              Comment


              • #8
                SUCCESS !!!

                LOVE IT!

                Greig,

                Got it to work.....

                I had to leave the Serial.begin(xx) at the HSSetup and comment the rest of Serial.print commands and everything works!

                I also got a good idea from user "logbuilder" and his code..

                Once I have everything up I will share in the Projects section.

                Thanks for all your help!
                Chris

                Comment

                Working...
                X