Announcement

Collapse
No announcement yet.

Constant error message in HS Log

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

  • FernandoSolanes
    replied
    Thank you, I will try this out. I should have apologized in advance, Im a copy paste user taking bits and pieces from others to try and get my stuff to work since i really am not a good coder.
    So I'm my code looks like it has things that don't make sense its not intentional

    Leave a comment:


  • enigmatheatre
    replied
    I am a little confused by your code:
    PHP Code:
    if (IsConnected == true) {

       
    digitalWrite(Output1,FromHS[0]);
       
    //digitalWrite(Output2,FromHS[1]);
       
    if(millis() - LastSend SendDelay){ 
    //****************Relay***************** 
        
    ami digitalRead(Input8); 
        
    SendToHS(1,ami);
    //****************Temperature DHT*****************       
        
    SendToHS(1,dht.readHumidity()); 
        
    SendToHS(2,dht.readTemperature()); 
        
         
    LastSend=millis(); 
        } 
      }

    In this code you are using SendToHS(1,ami); to send the status of pin 8 to the API input 1 device but then in the next line of code you are using SendToHS(1,dht.readHumidity()); to also send the Humidity reading to API input 1.


    I think the NAN is the sensor not having time to read the value or it is erroring out.

    Try this untested code:

    PHP Code:
    /********************************************************
      Arduino to Homeseer 3 Plugin written by Enigma Theatre.
       V1.0.0.134
     *                                                       *
     *******Do not Change any values below*******************
    */

    int Output1 5;
    //int Output2 = 6;

    #define ISIP 1
    #define ESP8266 1
    #include <EEPROM.h>
    #include <ESP8266WiFi.h>
    #include <WiFiUdp.h>

    const byte BoardAdd 7;

    byte mac[] = {0x000xAA0xBB0xCC0xDE0x07};
    IPAddress ip(192168137);     //IP entered in HS config.
    IPAddress gateway(19216811);     //Gateway
    IPAddress subnet(2552552550);     //Gateway
    IPAddress HomeseerIP(192168115); //Homeseer IP address
    IPAddress ServerIP(0,0,0,0);
    IPAddress LastRcvIP(0,0,0,0);
    char ssid[] = "myssid";  //  your network SSID (name)
    char pass[] = "mypassword";       // your network password
    const unsigned int localPort 8080;      //port entered in HS config.

    byte EEpromVersion EEPROM.read(250);


    //************Do not change anything in Here*****************
    int FromHS[10];                                          // *
    boolean IsConnected false;                             // *
    char packetBuffer[UDP_TX_PACKET_MAX_SIZE];               // *
    WiFiUDP Udp;                                             // *
    const unsigned int ServerPort 8888;                    // *
    void resetFunc() {   ESP.restart(); }

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

    #include <DHT.h> 
    #define DHTPIN 2
    #define DHTTYPE DHT22
    #define Input8 D8 

    DHT dht(DHTPINDHTTYPE); 

    int SendDelay 3000
    long LastSend
    int ami 1034;

    //************************************************************
    void setup() {
      
    HSSetup();

      
    dht.begin(); 
      
    pinMode(Output1OUTPUT);
      
    //pinMode(Output2, OUTPUT);
      
    pinMode(D8INPUT);
    }

    void loop() {

    IsUDP();

    if (
    IsConnected == true) {

       
    digitalWrite(Output1,FromHS[0]);
       
    //digitalWrite(Output2,FromHS[1]);
       
    if(millis() - LastSend SendDelay){ 
    //****************Relay***************** 
        
    ami digitalRead(Input8); 
        
    SendToHS(1,ami);
    //****************Temperature DHT*****************   

      // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
      
    float h dht.readHumidity();
      
    // Read temperature as Celsius (the default)
      
    float t dht.readTemperature();
      
          
    // Check if any reads failed and exit early (to try again).
      
    if (isnan(h) || isnan(t)) {
       return;
      }
        
    SendToHS(1,h); 
        
    SendToHS(2,t); 
        
         
    LastSend=millis(); 
        } 
      }
    }

    //************************************************************
    //************************************************************
    //************************************************************
    charVersion "API1.0.0.136";
    byte Byte1,Byte2,Byte3;
    int Byte4,Byte5;
    void HSSetup() {

      
    EEPROM.begin(256);
      
    EEpromVersion EEPROM.read(250);
      
    ServerIP IPAddress(EEPROM.read(2),EEPROM.read(3),EEPROM.read(4),EEPROM.read(5));

        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
        
    EEPROM.commit();
        
    EEpromVersion=22;
      }

      
    Serial.begin(115200);

      
    // We start by connecting to a WiFi network
      
    WiFi.begin(ssidpass);
      
    WiFi.config(ipgatewaysubnet);

      while (
    WiFi.status() != WL_CONNECTED) {
        
    delay(500);
      }

    Udp.begin(localPort);
    Udp.setTimeout(0);
    delay(1000);
    SendConnect();


    IsConnected false;

    }
    void SendConnect()
    {
    #if ISIP == 0
      
    Serial.print("Connect ");
      
    Serial.println(BoardAdd);
    #else
        
    Udp.beginPacket(ServerIP,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 IsUDP(){
      
    int packetSize Udp.parsePacket();
      if(
    packetSize)
      {
        
    LastRcvIP Udp.remoteIP();
        
    Byte1 =Udp.parseInt();
        
    Udp.read(); 
        
    Byte2 =Udp.read(); 
        
    Byte3 =Udp.parseInt();
        
    Byte4 =Udp.parseInt();
        
    Byte5 =Udp.parseInt();
        
    DataEvent();
      }
    }

    #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) {
        switch (
    Byte2) {

        case 
    'c':
          
    IsConnected true;
    #if ISIP == 1
          
    if (LastRcvIP != ServerIP) {
            
    ServerIP=LastRcvIP;
            
    EEPROM.write(2,ServerIP[0]);
            
    EEPROM.write(3,ServerIP[1]);
            
    EEPROM.write(4,ServerIP[2]);
            
    EEPROM.write(5,ServerIP[3]);
            
    #ifdef ESP8266
            
    EEPROM.commit();
            
    #endif
          
    }     
    #endif

          
    break;

        case 
    'C':   
    #if ISIP == 1
          
    Udp.beginPacket(LastRcvIPServerPort);
          
    Udp.print("Version ");
          
    Udp.print(BoardAdd);
          
    Udp.print(" ");
          
    Udp.print(Version);
          
    Udp.println(" HS3");
          
    Udp.endPacket();

          
    Udp.beginPacket(LastRcvIPServerPort);
          
    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(LastRcvIPServerPort);
          
    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]);
            
    #ifdef ESP8266
            
    EEPROM.commit();
            
    #endif
          
    }     
    #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 Devicelong Data){
    if (
    IsConnected == true) {
    #if ISIP == 1
      
    Udp.beginPacket(LastRcvIPServerPort);
      
    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 Deviceint Data){
    if (
    IsConnected == true) {
    #if ISIP == 1
      
    Udp.beginPacket(LastRcvIPServerPort);
      
    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 Devicefloat Data){
    if (
    IsConnected == true) {
    #if ISIP == 1
      
    Udp.beginPacket(LastRcvIPServerPort);
      
    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 Devicedouble Data){
    if (
    IsConnected == true) {
    #if ISIP == 1
      
    Udp.beginPacket(Udp.remoteIP(), 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
    }

    Greig.

    Leave a comment:


  • FernandoSolanes
    replied
    Code

    Code:
    /********************************************************
      Arduino to Homeseer 3 Plugin written by Enigma Theatre.
       V1.0.0.134
     *                                                       *
     *******Do not Change any values below*******************
    */
    
    int Output1 = 5;
    //int Output2 = 6;
    
    #define ISIP 1
    #define ESP8266 1
    #include <EEPROM.h>
    #include <ESP8266WiFi.h>
    #include <WiFiUdp.h>
    
    const byte BoardAdd = 7;
    
    byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x07};
    IPAddress ip(192, 168, 1, 37);     //IP entered in HS config.
    IPAddress gateway(192, 168, 1, 1);     //Gateway
    IPAddress subnet(255, 255, 255, 0);     //Gateway
    IPAddress HomeseerIP(192, 168, 1, 15); //Homeseer IP address
    IPAddress ServerIP(0,0,0,0);
    IPAddress LastRcvIP(0,0,0,0);
    char ssid[] = "myssid";  //  your network SSID (name)
    char pass[] = "mypassword";       // your network password
    const unsigned int localPort = 8080;      //port entered in HS config.
    
    byte EEpromVersion = EEPROM.read(250);
    
    
    //************Do not change anything in Here*****************
    int FromHS[10];                                          // *
    boolean IsConnected = false;                             // *
    char packetBuffer[UDP_TX_PACKET_MAX_SIZE];               // *
    WiFiUDP Udp;                                             // *
    const unsigned int ServerPort = 8888;                    // *
    void resetFunc() {   ESP.restart(); }
    
    //************************************************************
    //************************************************************
    //************************************************************
    
    #include <DHT.h> 
    #define DHTPIN 2
    #define DHTTYPE DHT22
    #define Input8 D8 
    
    DHT dht(DHTPIN, DHTTYPE); 
    
    int SendDelay = 3000; 
    long LastSend; 
    int ami = 1034;
    
    //************************************************************
    void setup() {
      HSSetup();
    
      dht.begin(); 
      pinMode(Output1, OUTPUT);
      //pinMode(Output2, OUTPUT);
      pinMode(D8, INPUT);
    }
    
    void loop() {
    
    IsUDP();
    
    if (IsConnected == true) {
    
       digitalWrite(Output1,FromHS[0]);
       //digitalWrite(Output2,FromHS[1]);
       if(millis() - LastSend > SendDelay){ 
    //****************Relay***************** 
        ami = digitalRead(Input8); 
        SendToHS(1,ami);
    //****************Temperature DHT*****************       
        SendToHS(1,dht.readHumidity()); 
        SendToHS(2,dht.readTemperature()); 
        
         LastSend=millis(); 
        } 
      }
    }
    
    //************************************************************
    //************************************************************
    //************************************************************
    char* Version = "API1.0.0.136";
    byte Byte1,Byte2,Byte3;
    int Byte4,Byte5;
    void HSSetup() {
    
      EEPROM.begin(256);
      EEpromVersion = EEPROM.read(250);
      ServerIP = IPAddress(EEPROM.read(2),EEPROM.read(3),EEPROM.read(4),EEPROM.read(5));
    
        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
        EEPROM.commit();
        EEpromVersion=22;
      }
    
      Serial.begin(115200);
    
      // We start by connecting to a WiFi network
      WiFi.begin(ssid, pass);
      WiFi.config(ip, gateway, subnet);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
      }
    
    Udp.begin(localPort);
    Udp.setTimeout(0);
    delay(1000);
    SendConnect();
    
    
    IsConnected = false;
    
    }
    void SendConnect()
    {
    #if ISIP == 0
      Serial.print("Connect ");
      Serial.println(BoardAdd);
    #else
        Udp.beginPacket(ServerIP,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 IsUDP(){
      int packetSize = Udp.parsePacket();
      if(packetSize)
      {
        LastRcvIP = Udp.remoteIP();
        Byte1 =Udp.parseInt();
        Udp.read(); 
        Byte2 =Udp.read(); 
        Byte3 =Udp.parseInt();
        Byte4 =Udp.parseInt();
        Byte5 =Udp.parseInt();
        DataEvent();
      }
    }
    
    #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) {
        switch (Byte2) {
    
        case 'c':
          IsConnected = true;
    #if ISIP == 1
          if (LastRcvIP != ServerIP) {
            ServerIP=LastRcvIP;
            EEPROM.write(2,ServerIP[0]);
            EEPROM.write(3,ServerIP[1]);
            EEPROM.write(4,ServerIP[2]);
            EEPROM.write(5,ServerIP[3]);
            #ifdef ESP8266
            EEPROM.commit();
            #endif
          }     
    #endif
    
          break;
    
        case 'C':   
    #if ISIP == 1
          Udp.beginPacket(LastRcvIP, ServerPort);
          Udp.print("Version ");
          Udp.print(BoardAdd);
          Udp.print(" ");
          Udp.print(Version);
          Udp.println(" HS3");
          Udp.endPacket();
    
          Udp.beginPacket(LastRcvIP, 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(LastRcvIP, 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]);
            #ifdef ESP8266
            EEPROM.commit();
            #endif
          }     
    #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(LastRcvIP, 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(LastRcvIP, 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(LastRcvIP, 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(Udp.remoteIP(), 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
    }
    }

    Leave a comment:


  • enigmatheatre
    replied
    Originally posted by FernandoSolanes View Post
    I have been having a problem for some time now which i never seem to get around to fixing.

    I have 7 Wemos (ESP8266) oards with DHT22 and Some with Relay's connecting to HS via the Arduino plugin.
    I get this message about once every 2 seconds or so..

    Arduino Plugin Error = Exception in RecievedAPIInput : Conversion from string "nan" to type 'Double' is not valid.

    Anyone have any Ideas?
    What is your Sketch sending as the plugin is not finding a number to be converted to the Value. NAN = Not a number. are you sending a string?

    Send me a debug log to look at if you can not sort this.

    Greig.

    Leave a comment:


  • FernandoSolanes
    started a topic Constant error message in HS Log

    Constant error message in HS Log

    I have been having a problem for some time now which i never seem to get around to fixing.

    I have 7 Wemos (ESP8266) oards with DHT22 and Some with Relay's connecting to HS via the Arduino plugin.
    I get this message about once every 2 seconds or so..

    Arduino Plugin Error = Exception in RecievedAPIInput : Conversion from string "nan" to type 'Double' is not valid.

    Anyone have any Ideas?
Working...
X