Navigation

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

    Best posts made by Toine33

    • RE: P1 not working when using Mysensors ?

      @mfalkvidd
      Thank you so much 😄 Finnaly it is working as it should do!

      #define MY_DEBUG 
      #define MY_RS485
      #define MY_RS485_DE_PIN 2
      #define MY_RS485_BAUD_RATE 19200
      #define MY_RS485_HWSERIAL Serial
      #define MY_NODE_ID 3
      
      #include <AltSoftSerial.h>
      #include <SPI.h>
      #include <MySensors.h>  
      
      AltSoftSerial altSerial;
      
      int msg[1];
      const uint64_t pipe = 0xE8E8F0F0E1LL;
      
      const int requestPin =  4;         
      char input; // incoming serial data (byte)
      bool readnextLine = false;
      #define BUFSIZE 500
      #define CHILD_ID_WATT 0
      #define CHILD_ID_KWH_LOW 1
      #define CHILD_ID_KWH_HIGH 2
      #define CHILD_ID_GAS 3
      #define CHILD_ID_CURRENT 4
      
      char buffer[BUFSIZE]; //Buffer for serial data to find \n .
      int bufpos = 0;
      long mEVLT = 0; //Meter reading Electrics - consumption low tariff
      long mEVHT = 0; //Meter reading Electrics - consumption high tariff
      long mEAV = 0;  //Meter reading Electrics - Actual consumption
      long mEAT = 0;  //Meter reading Electrics - Actual generated electricity (Solar panels)
      long mG = 0;   //Meter reading Gas
      
      
      MyMessage msgWatt(CHILD_ID_WATT, V_WATT);
      MyMessage msgKwhLow(CHILD_ID_KWH_LOW, V_KWH);      //Was V_KWH
      MyMessage msgKwhHigh(CHILD_ID_KWH_HIGH, V_KWH);     //Was V_KWH
      MyMessage msgGas(CHILD_ID_GAS, V_VOLUME);
      
      
      
      void setup() {
      //  Serial.begin(19200);
      //  delay(1000);
        
        altSerial.begin(9600);
        delay(1000);
      }
      
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Node", "1.0");
        present(CHILD_ID_WATT, S_POWER);
        present(CHILD_ID_KWH_LOW, S_POWER);
        present(CHILD_ID_KWH_HIGH, S_POWER);
        present(CHILD_ID_GAS, S_GAS);
      }
      
      
      
      void loop() {
        long tl = 0;
        long tld =0;
        if (altSerial.available()) {
            char input = altSerial.read();
            buffer[bufpos] = input&127;
            bufpos++;
            if (input == '\n') { // We received a new line (data up to \n)
              // 1-0:1.8.2 = Electricity consumption high tariff (DSMR v4.0)
      
              
              if (sscanf(buffer,"1-0:1.8.2(%ld.%ld" , &tl, &tld) >0 ) {
                tl *= 1000;
                tl += tld;
                mEVHT = tl;
                //mEVHT = tl * 1000 + tld;
                if (mEVHT > 0) {
        
                  //mEVHT = 0;
                }
              }
        
        
      
              if (sscanf(buffer,"1-0:1.8.1(%ld.%ld" ,&tl, &tld)==2){
                tl *= 1000;
                tl += tld;
                mEVLT = tl;
        
                if (mEVLT > 0) {
        
        
                }
              }
      
      
        
              // 1-0:1.7.0 = Electricity consumption actual usage (DSMR v4.0)
              if (sscanf(buffer,"1-0:1.7.0(%ld.%ld" ,&tl , &tld) == 2)
              { 
                mEAV = (tl*1000)+tld*10;            
                if (mEAV > 0) {
        
                }
              }
      
      
      
      
      //Gastand uitlezen
      
      if (sscanf(buffer,"(%ld.%ld" , &tl, &tld)==2 ) 
            {   mG = (tl*1000.0)+tld;
            mG = mG;
            }
      
      
      
      
        
              // Empty buffer again (whole array)
              for (int i=0; i<500; i++)
              { 
                buffer[i] = 0;
              }
              bufpos = 0;
        
            }
             
            if (input == '!') {   //uitroepteken geeft einde van telegram aan, dus we gaan data versturen
              #ifdef DEBUG
                printData();
              #endif
              send(msgWatt.set(mEAV));
              send(msgKwhLow.set(mEVLT / 1000.0, 3)); 
              send(msgKwhHigh.set(mEVHT / 1000.0, 3));
              send(msgGas.set(mG / 1000.0, 3));
              mEVHT=0;
              mEVLT = 0;
              mEAV = 0;
              mG = 0;
              //client.stop();
            } //Einde vraagteken detectie   
        
          } 
      
      }
      
      
       
      

      And here an picture how it is showing up in domoticz:

      0_1568053520513_cc789582-9497-47ae-a278-d906a1b3a0fd-image.png

      posted in Troubleshooting
      Toine33
      Toine33
    • RE: BH1750 Lux Sensor Problems

      I guess i found it now,
      Looks like that V_LEVEL and V_LIGHT_LEVEL are both not behaving as expected,
      I have changed these now to V_TEXT after that the sensors was finaly working within domoticz.

      Also i had some cabeling issues, looks like the sensor doesnt like an cable length off 2 meter on 4x 0,44mm2 wire..
      Tommorow i am going to place the arduino closer to the weather station and i guess everything would be fine again then !

      Here my latest sketch:

      #define MY_DEBUG
      #define MY_RS485
      #define MY_RS485_DE_PIN 2
      #define MY_RS485_BAUD_RATE 19200
      #define MY_RS485_HWSERIAL Serial
      #define MY_NODE_ID 5
      
      
      #include <MySensors.h>  
      #include <BH1750.h>
      #include <Wire.h>
      
      #define CHILD_ID_LIGHT 25
      unsigned long SLEEP_TIME = 25000; // Sleep time between reads (in milliseconds)
      
      BH1750 lightSensor;
      
      // V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
      // If your controller supports the new V_LEVEL variable, use this instead for
      // transmitting LUX light level.
      // MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      MyMessage msg(CHILD_ID_LIGHT, V_TEXT);  
      uint16_t lastlux;
      
      void setup()  
      { 
        lightSensor.begin();
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Node 5", "1.0");
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_BINARY);
      }
      
      void loop()      
      {     
        uint16_t lux = lightSensor.readLightLevel();// Get Lux value
       // Serial.println(lux);
       // if (lux != lastlux) {
            send(msg.set(lux));
           // lastlux = lux;
       // }
      
        wait(SLEEP_TIME);
      }
      

      @Nca78
      Thanks for your help !

      posted in Troubleshooting
      Toine33
      Toine33