Navigation

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

    Posts made by peerkersezuuker

    • RE: FastLED / Neopixel (ws2811) Node, From Arduino code to Web page (with API)

      Hello,
      I know this is an old post.
      But i am trying the script getting to work in combination with Domoticz.
      A did a little rebuild to 2.1.0, and i am getting a RGD light which i can switch to dimmable in Domoticz.
      I can select color and dim the strip but i am struggeling with the Speed (V_VAR2) and Mode (V_VAR1).
      How can I adress these two in Domoticz so it is picked up by the node?
      So i want to set the mode and or the speed from Domoticz to.

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      // Enabled repeater feature for this node
      #define MY_REPEATER_FEATURE
      #define MY_NODE_ID 9
      
      #include <MySensors.h>
      #include <DHT.h>
      
      #include "FastLED.h"
      FASTLED_USING_NAMESPACE
      
      #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
      #warning "Requires FastLED 3.1 or later; check github for latest code."
      #endif
      
      #define DATA_PIN    3
      //#define CLK_PIN   4
      #define LED_TYPE    WS2811
      #define COLOR_ORDER GRB
      #define NUM_LEDS    60
      CRGB leds[NUM_LEDS];
      uint8_t gHue = 0;
      
      
      unsigned int currentSpeed = 0 ;
      int brightness = 96;
      unsigned int requestedMode = 0 ;
      int messageType = 0 ;
      int previousMessageType = -1;
      
      String hexColor = "000000" ;
      
      unsigned long previousTime = 0 ;
      
      void setup() {
        delay(1000);
        Serial.begin(115200);
        FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
        FastLED.setBrightness(brightness);
        FastLED.show();
      }
      
      void presentation() {
        sendSketchInfo("FastLED Node", "1.0");
        present(0, S_RGB_LIGHT, "Makes strip said color", true);
      }
      
      void loop() {
        switch (messageType) {
      
          //************** CASE 1 **************
          case (1):
            Serial.print("Hex color override: "); Serial.println(hexColor);
            colorWipe();
            messageType = 0 ;
            break;
      
          //************** CASE 2 **************
          case (2):
            if ( (previousTime + (long) currentSpeed ) < millis() ) {
              if (requestedMode == 2) {rainbow(); FastLED.show(); }
              if (requestedMode == 3) {rainbowWithGlitter();FastLED.show(); }
              if (requestedMode == 4) {addGlitter(80);FastLED.show(); }
              if (requestedMode == 5) {confetti();FastLED.show(); }
              if (requestedMode == 6) {sinelon();FastLED.show(); }
              if (requestedMode == 7) {bpm();FastLED.show(); }
              if (requestedMode == 8) {juggle();FastLED.show(); }
              previousTime = millis();
            }
            break;
      
          //************** CASE 3 **************
          case (3):   // Adjust timing of case 2 using non-blocking code (no DELAYs)
            Serial.print("Case 3 received. Speed set to: "); Serial.print(currentSpeed); Serial.println(" ms.");
            messageType = 2; 
            break;
      
          //************** CASE 4 **************
          case (4):   // Adjust brightness of whole strip of case 2 using non-blocking code (no DELAYs)
            Serial.print("Case 4 received. Brightness set to: "); Serial.println(brightness);
            FastLED.setBrightness(brightness); FastLED.show();
            messageType = previousMessageType ; // We get off type 4 ASAP
            break;
      
      
      
        }
      }
      
      void receive(const MyMessage &message) {
        Serial.println("Message received: ");
      
        if (message.type == V_RGB) { 
          messageType = 1 ;
          hexColor = message.getString();
          Serial.print("RGB color: "); Serial.println(hexColor);
          }
          
        if (message.type == V_VAR1) { 
          requestedMode = message.getInt();
          Serial.println(requestedMode);
          messageType = 2 ;
          Serial.print("Neo mode: "); Serial.println(requestedMode);
        }
      
        if (message.type == V_VAR2) { // This line is for the speed of said mode
          currentSpeed = message.getInt() ;
          Serial.println(currentSpeed);
          messageType = 3 ;
          Serial.print("Neo speed: "); Serial.println(currentSpeed);
        }
      
        if (message.type == V_VAR3) { // This line is for the brightness of said mode
          brightness = message.getInt() ;
          //if(brightness > 255) {brightness = 255;}
          //if(brightness < 0) {brightness = 0;}
          Serial.println(brightness);
          previousMessageType = messageType;
          messageType = 4 ;
          Serial.print("Neo brightness: "); Serial.println(brightness);
        }
      }
      
      
      //********************** FastLED FUNCTIONS ***********************
      
      
      void colorWipe() {
        for (int i = 0; i < NUM_LEDS ; i++) {
          leds[i] = strtol( &hexColor[0], NULL, 16);
          FastLED.show();
        }
      }
      
      void rainbow()
      {
        // FastLED's built-in rainbow generator
        fill_rainbow( leds, NUM_LEDS, gHue++, 7);
      }
      
      void rainbowWithGlitter()
      {
        // built-in FastLED rainbow, plus some random sparkly glitter
        fill_rainbow( leds, NUM_LEDS, gHue++, 7);
        FastLED.show();
        addGlitter(80);
      }
      
      void addGlitter( fract8 chanceOfGlitter)
      {
        if ( random8() < chanceOfGlitter) {
          leds[ random16(NUM_LEDS) ] += CRGB::White;
        }
        
      }
      
      void confetti()
      {
        // random colored speckles that blink in and fade smoothly
        fadeToBlackBy( leds, NUM_LEDS, 10);
        int pos = random16(NUM_LEDS);
        leds[pos] += CHSV( gHue + random8(64), 200, 255);
      }
      
      void sinelon()
      {
        // a colored dot sweeping back and forth, with fading trails
        fadeToBlackBy( leds, NUM_LEDS, 20);
        int pos = beatsin16(13, 0, NUM_LEDS);
        leds[pos] += CHSV( gHue, 255, 192);
      }
      
      void bpm()
      {
        // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
        uint8_t BeatsPerMinute = 62;
        CRGBPalette16 palette = PartyColors_p;
        uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
        for ( int i = 0; i < NUM_LEDS; i++) { //9948
          leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
        }
      }
      
      void juggle() {
        // eight colored dots, weaving in and out of sync with each other
        fadeToBlackBy( leds, NUM_LEDS, 20);
        byte dothue = 0;
        for ( int i = 0; i < 8; i++) {
          leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
          dothue += 32;
        }
      }
      

      With Regards, and thanks in advance.
      Peter

      posted in Node-RED
      peerkersezuuker
      peerkersezuuker
    • 12V AC dimming

      Hello, i have looked arround but i cant seem to find any examples.
      I want to dim 3 x 12v AC ledbulbs in my kitchen seiling, and i was wondering how to build one with Mysensor controll.
      So input is 12v AC, wich should feed the mysensor node (converting ac-> dc) and dim my 12V AC led bulbs.
      Any suggestions on this ?

      With regard's
      Peer van Hoek

      posted in General Discussion
      peerkersezuuker
      peerkersezuuker
    • RE: lost serial gateway after un plug power Rpi

      Thank's for the answers to this problem.
      They didn't work for me, but i think i solved mine.
      Stop monitoring the serial port for data from a terminal session.
      See my post at Domoticz forum.

      posted in Domoticz
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      @Jan-Gatzke
      Sure, no problem.
      But it is not 100% clean, i am just a coppier and paste'r....
      If you can clean it up that would be nice.

      /**
      Based on the MySensors Project: http://www.mysensors.org
      
      This sketch controls a (analog)RGBW strip by listening to new color values from a (domoticz) controller and then fading to the new color.
      
      Version 1.0 - Changed pins and gw definition
      Version 0.9 - Oliver Hilsky
      
      TODO
      safe/request values after restart/loss of connection
      */
      #define MY_DEBUG 
      
      #define SN   "RGBW 01"
      #define SV   "1.0"
      #define MY_RADIO_NRF24
      // change the pins to free up the pwm pin for led control
      #define MY_RF24_CE_PIN 4 //<-- NOTE!!! changed, the default is 9
      #define MY_RF24_CS_PIN 10 // default is 10
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      #define MY_REPEATER_FEATURE
      #define MY_NODE_ID 6
      
      
      // Load mysensors library	
      #include <MySensors.h>	
      // Load Serial Peripheral Interface library  
      #include <SPI.h>
      
      // Arduino pin attached to driver pins
      #define RED_PIN 3 
      #define WHITE_PIN 9
      #define GREEN_PIN 5
      #define BLUE_PIN 6
      #define NUM_CHANNELS 4 // how many channels, RGBW=4 RGB=3...
      #define CHILD_ID 1
      
      // Smooth stepping between the values
      #define STEP 1
      #define INTERVAL 10
      const int pwmIntervals = 255;
      float R; // equation for dimming curve
      
      // Stores the current color settings
      byte channels[4] = {RED_PIN, GREEN_PIN, BLUE_PIN, WHITE_PIN};
      byte values[4] = {0, 0, 0, 255};
      byte target_values[4] = {0, 0, 0, 255}; 
      
      
      // stores dimming level
      byte dimming = 100;
      byte target_dimming = 100;
      
      // tracks if the strip should be on of off
      boolean isOn = true;
      
      // time tracking for updates
      unsigned long lastupdate = millis();
           
      void setup() 
      {
        // Initializes the sensor node (with callback function for incoming messages)
        //begin(incomingMessage);	// 123 = node id for testing	
             
        // Set all channels to output (pin number, type)
        for (int i = 0; i < NUM_CHANNELS; i++) {
          pinMode(channels[i], OUTPUT);
        }
      
        // set up dimming
        R = (pwmIntervals * log10(2))/(log10(255));
      
        // get old values if this is just a restart
        request(CHILD_ID, V_RGBW);
      
        // init lights
        updateLights();
        
        // debug
        if (isOn) {
          Serial.println("RGBW is running...");
        }
       
        Serial.println("Waiting for messages...");  
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
      
        // Register this device as Waterflow sensor
        present(CHILD_ID, S_RGBW_LIGHT, SN, true);
      }
      
      void loop()
      {
        // Process incoming messages (like config and light state from controller) - basically keep the mysensors protocol running
      //  process();		
      
        // and set the new light colors
        if (millis() > lastupdate + INTERVAL) {
          updateLights();
          lastupdate = millis();
        } 
      }
      
      // callback function for incoming messages
      void receive(const MyMessage &message) {
      
        Serial.print("Got a message - ");
        Serial.print("Messagetype is: ");
        Serial.println(message.type);
      
        // acknoledgment
        if (message.isAck())
        {
         	Serial.println("Got ack from gateway");
        }
        
        // new dim level
        else if (message.type == V_DIMMER) {
            Serial.println("Dimming to ");
            Serial.println(message.getString());
            target_dimming = message.getByte();
      
            // a new dimmer value also means on, no seperate signal gets send (by domoticz)
          isOn = true;
        }
      
        // on / off message
        else if (message.type == V_STATUS) {
          Serial.print("Turning light ");
      
          isOn = message.getInt();
      
          if (isOn) {
            Serial.println("on");
          } else {
            Serial.println("off");
          }
        }
      
        // new color value
        else if (message.type == V_RGBW) {    
          const char * rgbvalues = message.getString();
          inputToRGBW(rgbvalues);  
      
          // a new color also means on, no seperate signal gets send (by domoticz); needed e.g. for groups
          isOn = true;  
        }  
      }
      
      // this gets called every INTERVAL milliseconds and updates the current pwm levels for all colors
      void updateLights() {  
      
        // update pin values -debug
        //Serial.println(greenval);
        //Serial.println(redval);
        //Serial.println(blueval);
        //Serial.println(whiteval);
      
        //Serial.println(target_greenval);
        //Serial.println(target_redval);
        //Serial.println(target_blueval);
        //Serial.println(target_whiteval);
        //Serial.println("+++++++++++++++");
      
        // for each color
        for (int v = 0; v < NUM_CHANNELS; v++) {
      
          if (values[v] < target_values[v]) {
            values[v] += STEP;
            if (values[v] > target_values[v]) {
              values[v] = target_values[v];
            }
          }
      
          if (values[v] > target_values[v]) {
            values[v] -= STEP;
            if (values[v] < target_values[v]) {
              values[v] = target_values[v];
            }
          }
        }
      
        // dimming
        if (dimming < target_dimming) {
          dimming += STEP;
          if (dimming > target_dimming) {
            dimming = target_dimming;
          }
        }
        if (dimming > target_dimming) {
          dimming -= STEP;
          if (dimming < target_dimming) {
            dimming = target_dimming;
          }
        }
      
        /*
        // debug - new values
        Serial.println(greenval);
        Serial.println(redval);
        Serial.println(blueval);
        Serial.println(whiteval);
      
        Serial.println(target_greenval);
        Serial.println(target_redval);
        Serial.println(target_blueval);
        Serial.println(target_whiteval);
        Serial.println("+++++++++++++++");
        */
      
        // set actual pin values
        for (int i = 0; i < NUM_CHANNELS; i++) {
          if (isOn) {
            // normal fading
            analogWrite(channels[i], dimming / 100.0 * values[i]);
      
            // non linear fading, idea from https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms/
            //analogWrite(channels[i], pow (2, (dimming / R)) - 1);
          } else {
            analogWrite(channels[i], 0);
          }
        }
      }
      
      // converts incoming color string to actual (int) values
      // ATTENTION this currently does nearly no checks, so the format needs to be exactly like domoticz sends the strings
      void inputToRGBW(const char * input) {
        Serial.print("Got color value of length: "); 
        Serial.println(strlen(input));
        
        if (strlen(input) == 6) {
          Serial.println("new rgb value");
          target_values[0] = fromhex (& input [0]);
          target_values[1] = fromhex (& input [2]);
          target_values[2] = fromhex (& input [4]);
          target_values[3] = 0;
        } else if (strlen(input) == 9) {
          Serial.println("new rgbw value");
          target_values[0] = fromhex (& input [1]); // ignore # as first sign
          target_values[1] = fromhex (& input [3]);
          target_values[2] = fromhex (& input [5]);
          target_values[3] = fromhex (& input [7]);
        } else {
          Serial.println("Wrong length of input");
        }  
      
      
        Serial.print("New color values: ");
        Serial.println(input);
        
        for (int i = 0; i < NUM_CHANNELS; i++) {
          Serial.print(target_values[i]);
          Serial.print(", ");
        }
       
        Serial.println("");
        Serial.print("Dimming: ");
        Serial.println(dimming);
      }
      
      // converts hex char to byte
      byte fromhex (const char * str)
      {
        char c = str [0] - '0';
        if (c > 9)
          c -= 7;
        int result = c;
        c = str [1] - '0';
        if (c > 9)
          c -= 7;
        return (result << 4) | c;
      }```
      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      @Jan-Gatzke
      Thank you, i see it in the code now ...
      I tested it with setting the RGB levels one by one to 255, and this works, so the channels are responding to the initialisation code.
      And because it is rebuild to version 2.0, i forgot one void to adjust...
      void incomingMessage(
      should be
      void receive(

      Problem solved, thank you very much.
      With regards
      Peer van Hoek

      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      A little question, the v1.3 is this the one with the corrected mosfet placement ?
      I build and programmed one now, but i only get a bright white light, and no response when i switch the node. So now i am in doubt...

      With regards
      Peer

      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: lost serial gateway after un plug power Rpi

      I have the same problem, i posted a question at the Domoticz Forum :
      Not reconnecting serial portt

      Greetz Peer

      posted in Domoticz
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      @Jan-Gatzke
      Thank you for your post.
      I hope the Mosfet's are comming in today, then i can build it up and play with it.

      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      @Jan-Gatzke
      Hi can you please post your adjusted sketch for further reference?

      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: 💬 OH MySensors RGBW Controller

      Just got the v1.3 pcb's from OSH Park, just waiting for some components, and the we go. It will be an exciting christmas 😉

      posted in OpenHardware.io
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      Back to the weather station.
      I was having problems reporting wind speed to domoticz (in hardware my sensor was listed, but there was no device creation)
      After a question on their forum, i learned tha i had to implement gust and direction to the sensor becaus Domoticz is aspectiong these to before it vreates a device.
      I had to remove the rainrate because the sketch was getting to big.
      Here is the latest sketch i am using :

      
      
      
          #include <SPI.h>
          #include <MySensor.h>  
          #include <dht.h>
          #include <BH1750.h>
          #include <Wire.h> 
          #include <Adafruit_BMP085.h>
          #include <MySigningAtsha204.h>
          
          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define CHILD_ID_LIGHT 2
          #define CHILD_ID_BARO 3
          #define CHILD_ID_BTEMP 4
          #define CHILD_ID_WINDSPEED 5
          #define CHILD_ID_RAIN 6
          
          #define MESSAGEWAIT 500
          #define DIGITAL_INPUT_RAIN_SENSOR 3
          #define HUMIDITY_SENSOR_DIGITAL_PIN 5
          #define ENCODER_PIN 2
          #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
      
          const int  windSpeedPin = 2; // contact on pin 2 digital
          int windSpeedPinCounter = 0; // impuls counter
          int windSpeedPinStatus = 0; // actual impuls
          int windSpeedPinStatusAlt = 0; // oude Impuls-Status
          unsigned long windmeterStart;
          unsigned long windmeterStartAlt = 0;
          int windSpeed; // Variable voor Wind Speed
          int beaufort = 0; // Variable Wind in Beaufort
          const int windmeterTime = 10000;
          //float knoten = 0.0;
          //float wind = 0.0;
          unsigned int knoten;
          unsigned int wind;
         
          boolean metric = false;
          int altitude = 16; // meters above sealevel
          float lastBmpTemp = -1;
          float lastPressure = -1;
          float lastHum = -1;
          float lastTemp = -1;
          double temp;
          double hum;
          int BATTERY_SENSE_PIN = A0;
          int lastRainValue = -1;
          int nRainVal;
          boolean bIsRaining = false;
          String strRaining = "NO";
          int lastBatteryPcnt = 0;
          int updateAll = 60;
          int updateCount = 0;
          uint16_t lastLux;
          // unsigned long SLEEP_TIME = 60000;
          unsigned long SLEEP_TIME = 600;
          int batteryBasement = 800;
          float batteryConstant = 100.0 / (1023 - batteryBasement);
      
          MyTransportNRF24 radio;  // NRFRF24L01 radio driver
          MyHwATMega328 hw; // Select AtMega328 hardware profile
          MySigningAtsha204 signer(true); // Select HW ATSHA signing backend
          
          Adafruit_BMP085 bmp = Adafruit_BMP085();
          BH1750 lightSensor;
          dht DHT;
          MySensor gw(radio, hw, signer);
      
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
          MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
          MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
          MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);
          MyMessage msgWGust(CHILD_ID_WINDSPEED, V_GUST);
          MyMessage msgWDirection(CHILD_ID_WINDSPEED, V_DIRECTION);   
          MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
      
          void setup()  
          {
            analogReference(INTERNAL);
            gw.begin(incomingMessage, 3, true);  
            //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
            bmp.begin();
            gw.sendSketchInfo("Weather Sensor", "1.0");
            gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
            gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
            gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
            gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
            gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
            gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
            gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
      
            pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
            lightSensor.begin();
            metric = gw.getConfig().isMetric;
          }
          
          // Wind Meter https://github.com/chiemseesurfer/arduinoWeatherstation/blob/master/weatherstation/weatherstation.ino
          
          float windmeter()
          {
              windmeterStart = millis(); // Actual start time measuringMessung
              windmeterStartAlt = windmeterStart; // Save start time
          
              windSpeedPinCounter = 0; // Set pulse counter to 0
              windSpeedPinStatusAlt = HIGH; // Set puls status High
          
              while ((windmeterStart - windmeterStartAlt) <= windmeterTime) // until 10000 ms (10 Seconds) ..
              {
                  windSpeedPinStatus = digitalRead(windSpeedPin); // Read input pin 2
                  if (windSpeedPinStatus != windSpeedPinStatusAlt) // When the pin status changed
                  {
                      if (windSpeedPinStatus == HIGH) // When status - HIGH
                      {
                          windSpeedPinCounter++; // Counter + 1
                      }
                  }
                  windSpeedPinStatusAlt = windSpeedPinStatus; // Save status for next loop
                  windmeterStart = millis(); // Actual time
              }
          
              windSpeed =  ((windSpeedPinCounter * 24) / 10) + 0.5; //  WindSpeed - one Pulse ~ 2,4 km/h, 
              windSpeed = (windSpeed / (windmeterTime / 1000)); // Devided in measure time in seconds
              Serial.print("wind Speed : ");
              Serial.println(windSpeed);    
              knoten = windSpeed / 1.852; //knot's
          
              return windSpeed;
          }
          
          void loop()      
          {
            updateCount += 1;
            if (updateCount == updateAll) {
              lastTemp = -1;
              lastHum = -1;
              lastLux = -1;
              lastBmpTemp = -1;
              lastPressure = -1;
              lastRainValue = -1;
              lastBatteryPcnt = -1;
              updateCount = 0;
            }
            delay(2000);
            int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
            temp = DHT.temperature;
                   //Serial.print("Temperature DHT :");
                   //Serial.println(temp);
            if (isnan(temp)) {
                lastTemp = -1;
            } else if (temp != lastTemp) {
              lastTemp = temp;
              if (!metric) {
                temp = temp * 1.8 + 32.0;
              }
              gw.send(msgTemp.set(temp, 1));
              }
            hum = DHT.humidity;
            if (isnan(hum)) {
                lastHum = -1;
            } else if (hum != lastHum) {
                lastHum = hum;
                gw.send(msgHum.set(hum, 1));
            }
            uint16_t lux = lightSensor.readLightLevel();
            if (lux != lastLux) {
                gw.send(msgLux.set(lux));
                lastLux = lux;
            }
            float pressure = bmp.readSealevelPressure(altitude) * 0.01;
            float bmptemp = bmp.readTemperature();
            if (!metric) {
              bmptemp = bmptemp * 1.8 + 32.0;
            }
            if (bmptemp != lastBmpTemp) {
              gw.send(msgBtemp.set(bmptemp,1));
              lastBmpTemp = bmptemp;
            }
            if (pressure != lastPressure) {
              gw.send(msgPressure.set(pressure, 0));
              lastPressure = pressure;
            }
            
            bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
            if(bIsRaining){
                strRaining = "YES";
            }
            else{
                strRaining = "NO";
            }
        
            //Serial.print("Raining?: ");
            //Serial.print(strRaining);  
            //Serial.print("\t Moisture Level: ");
            //Serial.println(nRainVal);
            //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
      
            gw.send(msgRain.set(bIsRaining, 1));
      
            wind = windmeter();
            Serial.print("Wind : ");
            Serial.println(wind);
            int wdirection = 1;
            int wgust = 1;
            gw.send(msgWindSpeed.set(wind, 1));
            gw.send(msgWGust.set(wgust, 1));
            gw.send(msgWDirection.set(wdirection, 1));
            
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
            if (lastBatteryPcnt != batteryPcnt) {
              gw.sendBatteryLevel(batteryPcnt);
              lastBatteryPcnt = batteryPcnt;
            }
            gw.sleep(SLEEP_TIME);
         }
      
          void incomingMessage(const MyMessage & message) {
          // We only expect one type of message from controller. But we better check anyway.
           if (message.isAck()) {
             Serial.println("This is an ack from gateway");
           }
          }
      
      

      regards Peer

      posted in My Project
      peerkersezuuker
      peerkersezuuker
    • Signing (Hardware) not working, don't know it anymore

      Hello,
      First of all i want say MySensors is very great and fun to do.
      And with signing implemented it's a realy mature product (if it only would work...).
      I have read the complete signing post but i can't figure out why it is not working.
      Precious i build an RGB controller and without implementing signing it works.
      Now i want to implement signing and it won't work.
      Here is the log from the gateway :

      0;0;3;0;9;read: 3-3-0 s=5,c=1,t=8,pt=2,l=2,sg=0:0
      3;5;1;0;8;0
      0;0;3;0;9;send: 0-0-0-0 s=0,c=1,t=2,pt=0,l=1,sg=0,st=fail:1
      0;0;3;0;9;read: 3-3-0 s=3,c=1,t=4,pt=7,l=5,sg=0:1008
      3;3;1;0;4;1008
      0;0;3;0;9;read: 3-3-0 s=6,c=1,t=16,pt=2,l=2,sg=0:1
      3;6;1;0;16;1
      0;0;3;0;9;read: 3-3-0 s=7,c=1,t=6,pt=2,l=2,sg=0:-1023
      3;7;1;0;6;-1023
      0;0;3;0;9;send: 0-0-2-2 s=0,c=3,t=16,pt=0,l=0,sg=0,st=ok:
      0;0;3;0;9;read: 3-3-0 s=5,c=1,t=8,pt=2,l=2,sg=0:0
      3;5;1;0;8;0
      0;0;3;0;9;sign fail
      0;0;3;0;9;read: 3-3-0 s=3,c=1,t=4,pt=7,l=5,sg=0:1008
      3;3;1;0;4;1008
      0;0;3;0;9;read: 3-3-0 s=6,c=1,t=16,pt=2,l=2,sg=0:1
      3;6;1;0;16;1
      0;0;3;0;9;read: 3-3-0 s=7,c=1,t=6,pt=2,l=2,sg=0:-1023
      3;7;1;0;6;-1023
      0;0;3;0;9;send: 0-0-2-2 s=0,c=3,t=16,pt=0,l=0,sg=0,st=ok:
      0;0;3;0;9;read: 2-2-0 s=255,c=3,t=17,pt=6,l=25,sg=0:019613760F72635FB
      0;0;3;0;9;send: 0-0-2-2 s=0,c=1,t=2,pt=0,l=1,sg=1,st=ok:1
      0;0;3;0;9;read: 3-3-0 s=5,c=1,t=8,pt=2,l=2,sg=0:0
      3;5;1;0;8;0
      0;0;3;0;9;send: 0-0-2-2 s=0,c=3,t=16,pt=0,l=0,sg=0,st=ok:
      0;0;3;0;9;read: 2-2-0 s=255,c=3,t=17,pt=6,l=25,sg=0:019613760F72635FB
      0;0;3;0;9;send: 0-0-2-2 s=0,c=1,t=40,pt=0,l=6,sg=1,st=ok:FF006B
      0;0;3;0;9;send: 0-0-2-2 s=0,c=3,t=16,pt=0,l=0,sg=0,st=ok:
      0;0;3;0;9;read: 3-3-0 s=3,c=1,t=4,pt=7,l=5,sg=0:1008
      3;3;1;0;4;1008
      0;0;3;0;9;read: 3-3-0 s=6,c=1,t=16,pt=2,l=2,sg=0:1
      3;6;1;0;16;1
      0;0;3;0;9;read: 3-3-0 s=7,c=1,t=6,pt=2,l=2,sg=0:-1023
      3;7;1;0;6;-1023
      0;0;3;0;9;read: 2-2-0 s=255,c=3,t=17,pt=6,l=25,sg=0:019613760F72635FB
      0;0;3;0;9;send: 0-0-2-2 s=0,c=1,t=3,pt=0,l=3,sg=1,st=ok:100
      0;0;3;0;9;read: 3-3-0 s=5,c=1,t=8,pt=2,l=2,sg=0:0
      3;5;1;0;8;0
      0;0;3;0;9;read: 3-3-0 s=3,c=1,t=4,pt=7,l=5,sg=0:1008
      3;3;1;0;4;1008
      0;0;3;0;9;read: 3-3-0 s=6,c=1,t=16,pt=2,l=2,sg=0:1
      3;6;1;0;16;1
      0;0;3;0;9;read: 3-3-0 s=7,c=1,t=6,pt=2,l=2,sg=0:-1023
      3;7;1;0;6;-1023
      0;0;3;0;9;read: 3-3-0 s=5,c=1,t=8,pt=2,l=2,sg=0:0
      3;5;1;0;8;0
      

      The gateway seems to send signed commands (sg=1)
      Here is the log from my RGB controller :

      send: 2-2-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:1
      read: 0-0-2 s=255,c=3,t=15,pt=2,l=2,sg=0:0
      send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4
      send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      sensor started, id=2, parent=0, distance=1
      send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=9,sg=0,st=ok:RGB_STRIP
      send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
      send: 2-2-0-0 s=0,c=0,t=26,pt=0,l=9,sg=0,st=ok:RGB Strip
      send: 2-2-0-0 s=0,c=2,t=40,pt=0,l=0,sg=0,st=ok:
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      verify fail
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      verify fail
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      verify fail
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      verify fail
      read: 0-0-2 s=0,c=3,t=16,pt=0,l=0,sg=0:
      send: 2-2-0-0 s=255,c=3,t=17,pt=6,l=25,sg=0,st=ok:019613760F72635FBDB44A5A0A63C39F12AF30F950A6EE5C97
      verify fail
      

      It looks like it is not receiving signed command's (sg=0) and giving Verify Fail, and the led's ar not burning up...
      Here is the sketch from the controller :

      #include <MySensor.h>
      #include <SPI.h>
      #include <MySigningAtsha204.h>
      
      #define BLUE_PIN 3
      #define GREEN_PIN 5
      #define RED_PIN 6
      
      #define NODE_ID 2
      #define CHILD_ID 0
      #define SKETCH_NAME "RGB_STRIP"
      #define SKETCH_VERSION "1.0"
      #define NODE_REPEAT false
      
      MyTransportNRF24 radio;  // NRFRF24L01 radio driver
      MyHwATMega328 hw; // Select AtMega328 hardware profile
      MySigningAtsha204 signer(true); // Select HW ATSHA signing backend
      
      MySensor gw(radio, hw, signer);
      
      long RGB_values[3] = {0, 0, 0};
      float dimmer;
      
      void setup() {
      
      
        pinMode(RED_PIN, OUTPUT);
        pinMode(GREEN_PIN, OUTPUT);
        pinMode(BLUE_PIN, OUTPUT);
      
        gw.begin(incomingMessage, NODE_ID, NODE_REPEAT);
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        gw.present(CHILD_ID, S_RGB_LIGHT, "RGB Strip", false);
        gw.request(CHILD_ID, V_RGB);
      }
      
      void loop() {
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message) {
      
        if (message.type == V_RGB) {
      
          String hexstring = message.getString();
          long number = (long) strtol( &hexstring[0], NULL, 16);
          RGB_values[0] = number >> 16;
          RGB_values[1] = number >> 8 & 0xFF;
          RGB_values[2] = number & 0xFF;
        }
        if (message.type == V_DIMMER) {
          dimmer = message.getInt();
          analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
          analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
          analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
        }
      
        if (message.type == V_LIGHT) {
          if (message.getInt() == 0) {
            digitalWrite(RED_PIN, 0);
            digitalWrite(GREEN_PIN, 0);
            digitalWrite(BLUE_PIN, 0);
      
          }
          if (message.getInt() == 1) {
            analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
            analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
            analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
          }
        }
      }
      
      

      And the sketch from the serial gateway :

      #define NO_PORTB_PINCHANGES  
      
      #include <MySigningNone.h>
      #include <MyTransportRFM69.h>
      #include <MyTransportNRF24.h>
      #include <MyHwATMega328.h>
      #include <MySigningAtsha204Soft.h>
      #include <MySigningAtsha204.h>
      
      #include <SPI.h>  
      #include <MyParserSerial.h>  
      #include <MySensor.h>  
      #include <stdarg.h>
      #include <PinChangeInt.h>
      #include "GatewayUtil.h"
      
      #define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
      #define INCLUSION_MODE_PIN  3 // Digital pin used for inclusion mode button
      #define RADIO_ERROR_LED_PIN 4  // Error led pin
      #define RADIO_RX_LED_PIN    6  // Receive led pin
      #define RADIO_TX_LED_PIN    5  // the PCB, on board LED
      
      // NRFRF24L01 radio driver (set low transmit power by default) 
      MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
      //MyTransportRFM69 transport;
      
      // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
      //MySigningNone signer;
      //MySigningAtsha204Soft signer;
      //MySigningAtsha204 signer;
      
      MySigningAtsha204 signer(false, 0); // Select HW ATSHA signing backend
      
      // Hardware profile 
      MyHwATMega328 hw;
      
      // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
      // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
      #ifdef WITH_LEDS_BLINKING
      MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
      #else
      //MySensor gw(transport, hw /*, signer*/);
      MySensor gw(transport, hw , signer);
      #endif
      
      char inputString[MAX_RECEIVE_LENGTH] = "";    // A string to hold incoming commands from serial/ethernet interface
      int inputPos = 0;
      boolean commandComplete = false;  // whether the string is complete
      
      void parseAndSend(char *commandBuffer);
      
      void output(const char *fmt, ... ) {
         va_list args;
         va_start (args, fmt );
         vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
         va_end (args);
         Serial.print(serialBuffer);
      }
      
        
      void setup()  
      { 
        gw.begin(incomingMessage, 0, true, 0);
      
        setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
      
        // Add interrupt for inclusion button to pin
        PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
      
      
        // Send startup log message on serial
        serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"),  C_INTERNAL, I_GATEWAY_READY);
      }
      
      void loop()  
      { 
        gw.process();
      
        checkButtonTriggeredInclusion();
        checkInclusionFinished();
        
        if (commandComplete) {
          // A command wass issued from serial interface
          // We will now try to send it to the actuator
          parseAndSend(gw, inputString);
          commandComplete = false;  
          inputPos = 0;
        }
      }
      
      
      /*
        SerialEvent occurs whenever a new data comes in the
       hardware serial RX.  This routine is run between each
       time loop() runs, so using delay inside loop can delay
       response.  Multiple bytes of data may be available.
       */
      void serialEvent() {
        while (Serial.available()) {
          // get the new byte:
          char inChar = (char)Serial.read(); 
          // if the incoming character is a newline, set a flag
          // so the main loop can do something about it:
          if (inputPos<MAX_RECEIVE_LENGTH-1 && !commandComplete) { 
            if (inChar == '\n') {
              inputString[inputPos] = 0;
              commandComplete = true;
            } else {
              // add it to the inputString:
              inputString[inputPos] = inChar;
              inputPos++;
            }
          } else {
             // Incoming message too long. Throw away 
              inputPos = 0;
          }
        }
      }
      
      

      I made the apropriate adjustment to the MyConfig.h :

      /**********************************
      *  Message Signing Settings
      ***********************************/
      // Disable to completly disable signing functionality in library
      #define MY_SIGNING_FEATURE
      
      // Define a suitable timeout for a signature verification session
      // Consider the turnaround from a nonce being generated to a signed message being received
      // which might vary, especially in networks with many hops. 5s ought to be enough for anyone.
      #define MY_VERIFICATION_TIMEOUT_MS 15000
      
      // Enable to turn on whitelisting
      // When enabled, a signing node will salt the signature with it's unique signature and nodeId.
      // The verifying node will look up the sender in a local table of trusted nodes and
      // do the corresponding salting in order to verify the signature.
      // For this reason, if whitelisting is enabled on one of the nodes in a sign-verify pair, both
      // nodes have to implement whitelisting for this to work.
      // Note that a node can still transmit a non-salted message (i.e. have whitelisting disabled)
      // to a node that has whitelisting enabled (assuming the receiver does not have a matching entry
      // for the sender in it's whitelist)
      //#define MY_SECURE_NODE_WHITELISTING
      
      // MySigningAtsha204 default setting
      #define MY_ATSHA204_PIN 17 // A3 - pin where ATSHA204 is attached
      
      // MySigningAtsha204Soft default settings
      #define MY_RANDOMSEED_PIN 7 // A7 - Pin used for random generation (do not connect anything to this)
      
      // Key to use for HMAC calculation in MySigningAtsha204Soft (32 bytes)
      #define MY_HMAC_KEY (Here is the key i generated with the personalizer)
      
      

      Both have the ATSHA204A soldered on A3 and are personalized with the key i generated with personalize sketch :

      #include <sha204_library.h>
      #include <sha204_lib_return_codes.h>
      
      // The pin the ATSHA204 is connected on
      #define ATSHA204_PIN 17 // A3
      
      // Uncomment this to enable locking the configuration zone.
      // *** BE AWARE THAT THIS PREVENTS ANY FUTURE CONFIGURATION CHANGE TO THE CHIP ***
      // It is still possible to change the key, and this also enable random key generation
      #define LOCK_CONFIGURATION
      
      // Uncomment this to enable locking the data zone.
      // *** BE AWARE THAT THIS PREVENTS THE KEY TO BE CHANGED ***
      // It is not required to lock data, key cannot be retrieved anyway, but by locking
      // data, it can be guaranteed that nobody even with physical access to the chip,
      // will be able to change the key.
      #define LOCK_DATA
      
      // Uncomment this to skip key storage (typically once key has been written once)
      //#define SKIP_KEY_STORAGE
      
      // Uncomment this to skip key data storage (once configuration is locked, key
      // will aways randomize)
      // Uncomment this to skip key generation and use 'user_key_data' as key instead.
      #define USER_KEY_DATA
      
      // Uncomment this for boards that lack UART
      // IMPORTANT: No confirmation will be required for locking any zones with this
      // configuration!
      // Also, key generation is not permitted in this mode as there is no way of
      // presenting the generated key.
      #define SKIP_UART_CONFIRMATION
      
      #if defined(SKIP_UART_CONFIRMATION) && !defined(USER_KEY_DATA)
      #error You have to define USER_KEY_DATA for boards that does not have UART
      #endif
      
      #ifdef USER_KEY_DATA
      #define MY_HMAC_KEY YOU WOULD LIKE TO,\
                          KNOW THIS WOULD YOU
      const uint8_t user_key_data[32] = {MY_HMAC_KEY};
      #endif
      
      

      I am a litle lost right now, any help would be appriciated.
      Why is my RGB controller nor responding to message's from the gateway.
      Why it keeps saying Verify Fail.
      With regard's
      Peer

      posted in Troubleshooting
      peerkersezuuker
      peerkersezuuker
    • RE: Marijuana detector module

      Calibration is the key, now find someone who is willing to blow some smoke in your sensor 😃

      posted in General Discussion
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      Oh yeah, a little source mentioning :
      Weather Station
      Weather Station Code

      Greetz Peer

      posted in My Project
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      So here it is :
      0_1459792588384_upload-3adeb2e3-0d4c-41e1-a7d7-e973e5081210

      And the code (still very rude but it works)

          #include <SPI.h>
          #include <MySensor.h>  
          #include <dht.h>
          #include <BH1750.h>
          #include <Wire.h> 
          #include <Adafruit_BMP085.h>
          
          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define CHILD_ID_LIGHT 2
          #define CHILD_ID_BARO 3
          #define CHILD_ID_BTEMP 4
          #define CHILD_ID_WINDSPEED 5
          #define CHILD_ID_RAIN 6
          #define CHILD_ID_RAINRATE 7    
          
          #define MESSAGEWAIT 500
          #define nRainIn A2
          #define DIGITAL_INPUT_RAIN_SENSOR 3
          #define HUMIDITY_SENSOR_DIGITAL_PIN 5
          #define ENCODER_PIN 2
          #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
      
          const int  windSpeedPin = 2; // contact on pin 2 digital
          int windSpeedPinCounter = 0; // impuls counter
          int windSpeedPinStatus = 0; // actual impuls
          int windSpeedPinStatusAlt = 0; // oude Impuls-Status
          unsigned long windmeterStart;
          unsigned long windmeterStartAlt = 0;
          int windSpeed; // Variable voor Wind Speed
          int beaufort = 0; // Variable Wind in Beaufort
          const int windmeterTime = 10000;
          //float knoten = 0.0;
          //float wind = 0.0;
          int knoten = 0.0;
          int wind = 0.0;
         
          boolean metric = false;
          int altitude = 16; // meters above sealevel
          float lastBmpTemp = -1;
          float lastPressure = -1;
          float lastHum = -1;
          float lastTemp = -1;
          double temp;
          double hum;
          int BATTERY_SENSE_PIN = A0;
          int lastRainValue = -1;
          int nRainVal;
          boolean bIsRaining = false;
          String strRaining = "NO";
          int lastBatteryPcnt = 0;
          int updateAll = 60;
          int updateCount = 0;
          uint16_t lastLux;
          // unsigned long SLEEP_TIME = 60000;
          unsigned long SLEEP_TIME = 600;
          int batteryBasement = 800;
          float batteryConstant = 100.0 / (1023 - batteryBasement);
              
          Adafruit_BMP085 bmp = Adafruit_BMP085();
          BH1750 lightSensor;
          dht DHT;
          MySensor gw;
      
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
          MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
          MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
          MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);    
          MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
          MyMessage msgRainRate(CHILD_ID_RAINRATE, V_RAIN);
      
          void setup()  
          {
            analogReference(INTERNAL);
            gw.begin(incomingMessage, 3, true);  
            //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
            bmp.begin();
            gw.sendSketchInfo("Weather Sensor", "1.0");
            gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
            gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
            gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
            gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
            gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
            gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
            gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
            gw.present(CHILD_ID_RAINRATE, S_RAIN, "WS RainRate");
      
            pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
            lightSensor.begin();
            metric = gw.getConfig().isMetric;
          }
          
          // Wind Meter https://github.com/chiemseesurfer/arduinoWeatherstation/blob/master/weatherstation/weatherstation.ino
          
          float windmeter()
          {
              windmeterStart = millis(); // Actual start time measuringMessung
              windmeterStartAlt = windmeterStart; // Save start time
          
              windSpeedPinCounter = 0; // Set pulse counter to 0
              windSpeedPinStatusAlt = HIGH; // Set puls status High
          
              while ((windmeterStart - windmeterStartAlt) <= windmeterTime) // until 10000 ms (10 Seconds) ..
              {
                  windSpeedPinStatus = digitalRead(windSpeedPin); // Read input pin 2
                  if (windSpeedPinStatus != windSpeedPinStatusAlt) // When the pin status changed
                  {
                      if (windSpeedPinStatus == HIGH) // When status - HIGH
                      {
                          windSpeedPinCounter++; // Counter + 1
                      }
                  }
                  windSpeedPinStatusAlt = windSpeedPinStatus; // Save status for next loop
                  windmeterStart = millis(); // Actual time
              }
          
              windSpeed =  ((windSpeedPinCounter * 24) / 10) + 0.5; //  WindSpeed - one Pulse ~ 2,4 km/h, 
              windSpeed = (windSpeed / (windmeterTime / 1000)); // Devided in measure time in seconds
              Serial.print("wind Speed :");
              Serial.println(windSpeed);    
              knoten = windSpeed / 1.852; //knot's
          
              return knoten;
          }
          
          void loop()      
          {
            updateCount += 1;
            if (updateCount == updateAll) {
              lastTemp = -1;
              lastHum = -1;
              lastLux = -1;
              lastBmpTemp = -1;
              lastPressure = -1;
              lastRainValue = -1;
              lastBatteryPcnt = -1;
              updateCount = 0;
            }
            delay(2000);
            int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
            temp = DHT.temperature;
                   //Serial.print("Temperature DHT :");
                   //Serial.println(temp);
            if (isnan(temp)) {
                lastTemp = -1;
            } else if (temp != lastTemp) {
              lastTemp = temp;
              if (!metric) {
                temp = temp * 1.8 + 32.0;
              }
              gw.send(msgTemp.set(temp, 1));
              }
            hum = DHT.humidity;
            if (isnan(hum)) {
                lastHum = -1;
            } else if (hum != lastHum) {
                lastHum = hum;
                gw.send(msgHum.set(hum, 1));
            }
            uint16_t lux = lightSensor.readLightLevel();
            if (lux != lastLux) {
                gw.send(msgLux.set(lux));
                lastLux = lux;
            }
            float pressure = bmp.readSealevelPressure(altitude) * 0.01;
            float bmptemp = bmp.readTemperature();
            if (!metric) {
              bmptemp = bmptemp * 1.8 + 32.0;
            }
            if (bmptemp != lastBmpTemp) {
              gw.send(msgBtemp.set(bmptemp,1));
              lastBmpTemp = bmptemp;
            }
            if (pressure != lastPressure) {
              gw.send(msgPressure.set(pressure, 0));
              lastPressure = pressure;
            }
            
            nRainVal = analogRead(nRainIn);
                   Serial.print("RainVal :");
                   Serial.println(nRainVal);
            bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
                   Serial.print("Is Raining :");
                   Serial.println(bIsRaining);
            if(bIsRaining){
                strRaining = "YES";
            }
            else{
                strRaining = "NO";
            }
        
            //Serial.print("Raining?: ");
            //Serial.print(strRaining);  
            //Serial.print("\t Moisture Level: ");
            //Serial.println(nRainVal);
            //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
      
            gw.send(msgRain.set(bIsRaining));
            nRainVal = nRainVal * -1;
            gw.send(msgRainRate.set(nRainVal));
      
            wind = windmeter();
            Serial.print("Wind :");
            Serial.println(wind);
            gw.send(msgWindSpeed.set(wind));
            
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
            if (lastBatteryPcnt != batteryPcnt) {
              gw.sendBatteryLevel(batteryPcnt);
              lastBatteryPcnt = batteryPcnt;
            }
            gw.sleep(SLEEP_TIME);
         }
      
          void incomingMessage(const MyMessage & message) {
          // We only expect one type of message from controller. But we better check anyway.
           if (message.isAck()) {
             Serial.println("This is an ack from gateway");
           }
          }```
      
      Still need some cleaning and calibrating (rain and wind sensor)
      [0_1459792799776_Weather-station.fzz](/uploads/files/1459792799984-weather-station.fzz) 
      
      Regard's Peer
      posted in My Project
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      @Elfnoir,
      Could you please send me the fritzing schema, or attach it here ?
      I want to add the windmeter i bought.
      I got it today, and with a little help from google i got it working.

      Greetz Peer

      posted in My Project
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      Hi,
      Commenting is done with //
      so //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
      The wind sensor is stil in shipment, so can't tell you anything about it, and i use Domoticz as controler software.
      I presume you have your gateway setup and connected, so the node should show up in domoticz with all the childs.
      I tested the the weather station only a few day's past monyh, because it is still under construction, but those day's it held out (I live near Eindhoven the Netherlands, so weather conditions are almost the same as yours ;-)).
      The battery reports through the potentiometer to A0, if the battery level = 100% the readout of A0 should be 1023 (adjustable with the portentio meter.
      Here is my sketch in total, althoug verry crude it works, it yust needs a lot of cleanup when i am done, but i need the sensor first to work.

         #include <SPI.h>
          #include <MySensor.h>  
          #include <dht.h>
          #include <BH1750.h>
          #include <Wire.h> 
          #include <Adafruit_BMP085.h>
          
          #define CHILD_ID_HUM 0
          #define CHILD_ID_TEMP 1
          #define CHILD_ID_LIGHT 2
          #define CHILD_ID_BARO 3
          #define CHILD_ID_BTEMP 4
          #define CHILD_ID_WINDSPEED 5
          #define CHILD_ID_RAIN 6
          #define CHILD_ID_RAINRATE 7    
          
          #define MESSAGEWAIT 500
          #define nRainIn A2
          #define DIGITAL_INPUT_RAIN_SENSOR 3
          #define HUMIDITY_SENSOR_DIGITAL_PIN 5
          #define ENCODER_PIN 2
          #define INTERRUPT DIGITAL_INPUT_RAIN_SENSOR-2
      
          //int encoder_pin = 7; // pulse output from the module
          unsigned int rpm; // rpm reading
          volatile byte pulses; // number of pulses
          unsigned long timeold;
          // number of pulses per revolution
          // based on your encoder disc
          unsigned int pulsesperturn = 1;
          boolean metric = false;
          int altitude = 16; // meters above sealevel
          float lastBmpTemp = -1;
          float lastPressure = -1;
          float lastHum = -1;
          float lastTemp = -1;
          double temp;
          double hum;
          int BATTERY_SENSE_PIN = A0;
          int lastRainValue = -1;
          int nRainVal;
          boolean bIsRaining = false;
          String strRaining = "NO";
          int lastBatteryPcnt = 0;
          int updateAll = 60;
          int updateCount = 0;
          uint16_t lastLux;
          // unsigned long SLEEP_TIME = 60000;
          unsigned long SLEEP_TIME = 600;
          int batteryBasement = 800;
          float batteryConstant = 100.0 / (1023 - batteryBasement);
              
          Adafruit_BMP085 bmp = Adafruit_BMP085();
          BH1750 lightSensor;
          dht DHT;
          MySensor gw;
      
          MyMessage msgHum(CHILD_ID_HUM, V_HUM);
          MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
          MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
          MyMessage msgBtemp(CHILD_ID_BTEMP, V_TEMP);
          MyMessage msgPressure(CHILD_ID_BARO, V_PRESSURE);
          MyMessage msgWindSpeed(CHILD_ID_WINDSPEED, V_WIND);    
          MyMessage msgRain(CHILD_ID_RAIN, V_TRIPPED);
          MyMessage msgRainRate(CHILD_ID_RAINRATE, V_RAIN);
      
          void counter()
          {
            //Update count
            pulses++;
          }
      
          void setup()  
          {
            analogReference(INTERNAL);
            gw.begin(incomingMessage, 3, true);  
            //dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
            bmp.begin();
            gw.sendSketchInfo("Weather Sensor", "1.0");
            gw.present(CHILD_ID_HUM, S_HUM, "WS Humidity");
            gw.present(CHILD_ID_TEMP, S_TEMP, "WS Temperature");
            gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL, "WS Lux");
            gw.present(CHILD_ID_BARO, S_BARO, "WS Pressure");
            gw.present(CHILD_ID_BTEMP, S_TEMP, "WS P Temperature");
            gw.present(CHILD_ID_WINDSPEED, S_WIND, "WS Windspeed");
            gw.present(CHILD_ID_RAIN, S_MOTION, "WS Rain");
            gw.present(CHILD_ID_RAINRATE, S_RAIN, "WS RainRate");
      
            pinMode(DIGITAL_INPUT_RAIN_SENSOR, INPUT);
            lightSensor.begin();
            metric = gw.getConfig().isMetric;
            pinMode(ENCODER_PIN, INPUT);
            //Interrupt 0 is digital pin 2
            //Triggers on Falling Edge (change from HIGH to LOW)
            attachInterrupt(0, counter, FALLING);
            // Initialize
            pulses = 0;
            rpm = 0;
            timeold = 0;
          }
          
          void loop()      
          {
            updateCount += 1;
            if (updateCount == updateAll) {
              lastTemp = -1;
              lastHum = -1;
              lastLux = -1;
              lastBmpTemp = -1;
              lastPressure = -1;
              lastRainValue = -1;
              lastBatteryPcnt = -1;
              updateCount = 0;
            }
            delay(2000);
            int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
            temp = DHT.temperature;
                   //Serial.print("Temperature DHT :");
                   //Serial.println(temp);
            if (isnan(temp)) {
                lastTemp = -1;
            } else if (temp != lastTemp) {
              lastTemp = temp;
              if (!metric) {
                temp = temp * 1.8 + 32.0;
              }
              gw.send(msgTemp.set(temp, 1));
              }
            hum = DHT.humidity;
            if (isnan(hum)) {
                lastHum = -1;
            } else if (hum != lastHum) {
                lastHum = hum;
                gw.send(msgHum.set(hum, 1));
            }
            uint16_t lux = lightSensor.readLightLevel();
            if (lux != lastLux) {
                gw.send(msgLux.set(lux));
                lastLux = lux;
            }
            float pressure = bmp.readSealevelPressure(altitude) * 0.01;
            float bmptemp = bmp.readTemperature();
            if (!metric) {
              bmptemp = bmptemp * 1.8 + 32.0;
            }
            if (bmptemp != lastBmpTemp) {
              gw.send(msgBtemp.set(bmptemp,1));
              lastBmpTemp = bmptemp;
            }
            if (pressure != lastPressure) {
              gw.send(msgPressure.set(pressure, 0));
              lastPressure = pressure;
            }
            
            nRainVal = analogRead(nRainIn);
                   Serial.print("RainVal :");
                   Serial.println(nRainVal);
            bIsRaining = !(digitalRead(DIGITAL_INPUT_RAIN_SENSOR));
                   Serial.print("Is Raining :");
                   Serial.println(bIsRaining);
            if(bIsRaining){
                strRaining = "YES";
            }
            else{
                strRaining = "NO";
            }
        
        //Serial.print("Raining?: ");
        //Serial.print(strRaining);  
        //Serial.print("\t Moisture Level: ");
        //Serial.println(nRainVal);
        //http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/arduino-rain-sensor-module-guide-and-tutorial/
      
            gw.send(msgRain.set(bIsRaining));
            nRainVal = nRainVal * -1;
            gw.send(msgRainRate.set(nRainVal));
            
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            int batteryPcnt = (sensorValue - batteryBasement) * batteryConstant;
            if (lastBatteryPcnt != batteryPcnt) {
              gw.sendBatteryLevel(batteryPcnt);
              lastBatteryPcnt = batteryPcnt;
           }
      
           if (millis() - timeold >= 1000) {
              //Don't process interrupts during calculations
              detachInterrupt(0);
              rpm = (60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses;
              timeold = millis();
              Serial.print("RPM = ");
              Serial.println(rpm,DEC);
              Serial.println(pulses);
              pulses = 0;        
              rpm = rpm,DEC;
              if (rpm == 0) {
                rpm = 1;
              }
              gw.send(msgWindSpeed.set(rpm, 1));
              //Restart the interrupt processing
              attachInterrupt(0, counter, FALLING);
            }
            gw.sleep(SLEEP_TIME);
          }
      
          void incomingMessage(const MyMessage & message) {
          // We only expect one type of message from controller. But we better check anyway.
           if (message.isAck()) {
             Serial.println("This is an ack from gateway");
           }
          }```
      And there is the puls counter which i abandoned for the wind speed meter (wanted to build my own with a optocoupler, but changed my mind).
      
      Hope this is helpfull.
      Regard's 
      Peer
      posted in My Project
      peerkersezuuker
      peerkersezuuker
    • RE: Solar Powered Mini-Weather Station

      Hello All,
      Long time reader, first time poster.
      I've been building my-sensors in combo with Domoticz for a while now , and this project is one of my favorites.
      I can confirm that the fritzing schema is correct, i checked it against the one i build. (whish i had the schema earlier, it would have been so much easier ;-))
      I used the followin library from Rob Tillaart for the DHT22 (http://playground.arduino.cc/Main/DHTLib / https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib) because the standard was not working...
      Change line 37 to dht DHT;
      comment out line 51
      From line 78 i changed the code to this :

      delay(2000);
            int chk = DHT.read22(HUMIDITY_SENSOR_DIGITAL_PIN);
            temp = DHT.temperature;
                   //Serial.print("Temperature DHT :");
                   //Serial.println(temp);
            if (isnan(temp)) {
                lastTemp = -1;
            } else if (temp != lastTemp) {
              lastTemp = temp;
              if (!metric) {
                temp = temp * 1.8 + 32.0;
              }
              gw.send(msgTemp.set(temp, 1));
              }
            hum = DHT.humidity;
            if (isnan(hum)) {
                lastHum = -1;
            } else if (hum != lastHum) {
                lastHum = hum;
                gw.send(msgHum.set(hum, 1));
            }
      

      And it is working like a charm.
      Now i ordered one of these : Wind Sensor
      I want to trie to get it working with this build.
      And indeed the lamp is stil available Solar Lamp

      Hope this helps,
      With Regard's
      Peer

      posted in My Project
      peerkersezuuker
      peerkersezuuker