Navigation

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

    Topics created by pepson

    • pepson

      How use mysensors to show in Home Assistant as LIGHT
      Home Assistant • • pepson  

      2
      0
      Votes
      2
      Posts
      40
      Views

      Dave Myers

      @pepson I have accomplished this in past within HomeAssistant using this component: https://www.home-assistant.io/integrations/light.switch/
    • pepson

      Multirelay for Home Assistant
      Development • • pepson  

      1
      0
      Votes
      1
      Posts
      598
      Views

      No one has replied

    • pepson

      Multirelay sketch-help with modification
      Development • • pepson  

      1
      0
      Votes
      1
      Posts
      563
      Views

      No one has replied

    • pepson

      Version 2.3.0 with RFM69HW - Problem communication
      Development • • pepson  

      2
      0
      Votes
      2
      Posts
      627
      Views

      pepson

      This is my sketch // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RFM69 #define MY_IS_RFM69HW #define RFM69_868MH #define MY_RFM69_NEW_DRIVER #define MY_REPEATER_FEATURE //#define MY_RFM69_CSMA_LIMIT_DBM (-85) // uncomment if we want to manually assign an ID #define MY_NODE_ID 1 #include <Bounce2.h> #include <MySensors.h> #include <SPI.h> #define BUTTON_UP_PIN 3 // Arduino Digital I/O pin number for up button #define BUTTON_DOWN_PIN 4 // Arduino Digital I/O pin number for down button //#define BUTTON_STOP_PIN 5 // Arduino Digital I/O pin number for stop button //#define RELAY_DIR_PIN 6 // Arduino Digital I/O pin number for direction relay //#define RELAY_POWER_PIN 7 // Arduino Digital I/O pin number for power relay #define RELAY_UP_PIN 5 #define RELAY_DOWN_PIN 6 #define RELAY_ON 0 #define RELAY_OFF 1 //#define RELAY_DOWN 1 //#define RELAY_UP 0 #define DIRECTION_DOWN 0 #define DIRECTION_UP 1 #define SKETCH_NAME "Roleta w sypialni" #define SKETCH_VER "2.3" #define CHILD_ID_COVER 0 // sensor Id of the sensor child #define STATE_UP 100 // 100 is open - up #define STATE_DOWN 0 // 0 is closed - down //#define CHILD_ID_CALIBRATE 1 // sensor Id of the sensor child to calibrate #define CHILD_ID_SET 1 // sensor Id of the sensor child to init the roll time #define PRESENT_MESSAGE "Rolety dla Home Assistant" const int LEVELS = 100; //the number of levels float rollTime = 20.0; //the overall rolling time of the shutter const bool IS_ACK = false; //is to acknowlage static bool initial_state_sent = false;//for hass we need at list one state send at begining // debouncing parameters int value = 0; int oldValueUp = 0; int oldValueDown = 0; int oldValueStop = 0; //static unsigned long last_interrupt_time_up = 0; //static unsigned long last_interrupt_time_down = 0; //static unsigned long debounce_time = 200; Bounce debouncerUp = Bounce(); Bounce debouncerDown = Bounce(); Bounce debouncerStop = Bounce(); // shutter position parameters float timeOneLevel = rollTime / LEVELS; int requestedShutterLevel = 0; int currentShutterLevel = 0; unsigned long lastLevelTime = 0; bool isMoving = false; int directionUpDown; bool calibrateDown; bool calibrateUp; unsigned long calibrationStartTime; float calibrationTime = 5.0; bool calibratedDown; bool calibratedUp; enum CoverState { STOP, UP, // Window covering. Up. DOWN, // Window covering. Down. }; static int coverState = STOP; MyMessage msgUp(CHILD_ID_COVER, V_UP); MyMessage msgDown(CHILD_ID_COVER, V_DOWN); MyMessage msgStop(CHILD_ID_COVER, V_STOP); MyMessage msgPercentage(CHILD_ID_COVER, V_PERCENTAGE); //MyMessage msgCode(CHILD_ID_SET, V_IR_SEND); void sendState() { // Send current state and status to gateway. // send(msgUp.set(coverState == UP)); // send(msgDown.set(coverState == DOWN)); // send(msgStop.set(coverState == STOP)); send(msgPercentage.set(currentShutterLevel)); } void shuttersUp(void) { #ifdef MY_DEBUG Serial.println("Shutters going up"); #endif if (digitalRead(RELAY_DOWN_PIN) == RELAY_ON) { digitalWrite(RELAY_DOWN_PIN, RELAY_OFF); wait(50); } digitalWrite(RELAY_UP_PIN, RELAY_ON); directionUpDown = DIRECTION_UP; isMoving = true; coverState = UP; sendState(); } void shuttersDown(void) { #ifdef MY_DEBUG Serial.println("Shutters going down"); #endif if (digitalRead(RELAY_UP_PIN) == RELAY_ON) { digitalWrite(RELAY_UP_PIN, RELAY_OFF); wait(50); } digitalWrite(RELAY_DOWN_PIN, RELAY_ON); directionUpDown = DIRECTION_DOWN; isMoving = true; coverState = DOWN; sendState(); } void shuttersHalt(void) { #ifdef MY_DEBUG Serial.println("Shutters halted"); #endif digitalWrite(RELAY_UP_PIN, RELAY_OFF); digitalWrite(RELAY_DOWN_PIN, RELAY_OFF); isMoving = false; requestedShutterLevel = currentShutterLevel; #ifdef MY_DEBUG Serial.println("saving state to: "); Serial.println(String(currentShutterLevel)); #endif saveState(CHILD_ID_COVER, currentShutterLevel); coverState = STOP; sendState(); } void changeShuttersLevel(int level) { int dir = (level > currentShutterLevel) ? DIRECTION_UP : DIRECTION_DOWN; if (isMoving && dir != directionUpDown) { shuttersHalt(); } requestedShutterLevel = level; } void initShutters() { #ifdef MY_DEBUG Serial.println("Init Cover"); #endif shuttersUp(); wait((rollTime + timeOneLevel * LEVELS) * 1000); currentShutterLevel = STATE_UP; requestedShutterLevel = currentShutterLevel; } void receive(const MyMessage &message) { #ifdef MY_DEBUG Serial.println("recieved incomming message"); Serial.println("Recieved message for sensor: "); Serial.println(String(message.sensor)); Serial.println("Recieved message with type: "); Serial.println(String(message.type)); #endif if (message.sensor == CHILD_ID_COVER) { switch (message.type) { case V_UP: //Serial.println(", New status: V_UP"); changeShuttersLevel(STATE_UP); //state = UP; //sendState(); break; case V_DOWN: //Serial.println(", New status: V_DOWN"); changeShuttersLevel(STATE_DOWN); //state = DOWN; //sendState(); break; case V_STOP: //Serial.println(", New status: V_STOP"); shuttersHalt(); //state = IDLE; //sendState(); break; case V_PERCENTAGE: //Serial.println(", New status: V_PERCENTAGE"); // if (!initial_state_sent) { // #ifdef MY_DEBUG // Serial.println("Receiving initial value from controller"); // #endif // initial_state_sent = true; // } int per = message.getInt(); if (per > STATE_UP) { per = STATE_UP; } changeShuttersLevel(per); //InitShutters(message.getInt());//send value < 0 or > 100 to calibrate //sendState(); break; } } else if (message.sensor == CHILD_ID_SET) { if (message.type == V_VAR1) { #ifdef MY_DEBUG Serial.println(", New status: V_VAR1, with payload: "); #endif String strRollTime = message.getString(); rollTime = strRollTime.toFloat(); #ifdef MY_DEBUG Serial.println("rolltime value: "); Serial.println(String(rollTime)); #endif saveState(CHILD_ID_SET, rollTime); } } #ifdef MY_DEBUG Serial.println("exiting incoming message"); #endif return; } void before() { // Setup the button pinMode(BUTTON_UP_PIN, INPUT_PULLUP); // Activate internal pull-up // digitalWrite(BUTTON_UP_PIN, HIGH); // attachInterrupt(digitalPinToInterrupt(BUTTON_UP_PIN), upButtonPress, FALLING); pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP); // Activate internal pull-up // digitalWrite(BUTTON_DOWN_PIN, HIGH); // attachInterrupt(digitalPinToInterrupt(BUTTON_DOWN_PIN), downButtonPress, FALLING); // pinMode(BUTTON_STOP_PIN, INPUT_PULLUP); // Activate internal pull-up // digitalWrite(BUTTON_STOP_PIN, HIGH); // After setting up the button, setup debouncer debouncerUp.attach(BUTTON_UP_PIN); debouncerUp.interval(5); // After setting up the button, setup debouncer debouncerDown.attach(BUTTON_DOWN_PIN); debouncerDown.interval(5); // After setting up the button, setup debouncer // debouncerStop.attach(BUTTON_STOP_PIN); // debouncerStop.interval(5); // Make sure relays are off when starting up digitalWrite(RELAY_UP_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_UP_PIN, OUTPUT); // Make sure relays are off when starting up digitalWrite(RELAY_DOWN_PIN, RELAY_OFF); // Then set relay pins in output mode pinMode(RELAY_DOWN_PIN, OUTPUT); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SKETCH_NAME, SKETCH_VER); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_COVER, S_COVER, PRESENT_MESSAGE, IS_ACK); // present(CHILD_ID_SET, S_CUSTOM); } void setup(void) { //set up roll time if the saved value is not 255 #ifdef MY_DEBUG Serial.println("getting rolltime from eeprom: "); #endif float tmpRollTime = loadState(CHILD_ID_SET); if (tmpRollTime != 0xff) { rollTime = tmpRollTime; } #ifdef MY_DEBUG Serial.println(String(rollTime)); #endif int state = loadState(CHILD_ID_COVER); #ifdef MY_DEBUG Serial.println("getting state from eeprom: "); Serial.println(String(state)); #endif // if (state == 0xff) { // initShutters(); // } else { currentShutterLevel = state; requestedShutterLevel = state; // } } void loop(void) { if (!initial_state_sent) { #ifdef MY_DEBUG Serial.println("Sending initial value"); #endif sendState(); // send(msgCode.set('20.0')); // #ifdef MY_DEBUG // Serial.println("Requesting initial value from controller"); // #endif // request(CHILD_ID_COVER, V_PERCENTAGE); // wait(2000, C_SET, V_PERCENTAGE); initial_state_sent = true; } debouncerUp.update(); value = debouncerUp.read(); if (value == 0 && value != oldValueUp) { if(isMoving){ shuttersHalt(); } else{ calibrateUp = false; calibratedUp = false; changeShuttersLevel(STATE_UP); } //state = UP; //sendState(); } oldValueUp = value; debouncerDown.update(); value = debouncerDown.read(); if (value == 0 && value != oldValueDown) { if(isMoving){ shuttersHalt(); } else{ calibrateDown = false; calibratedDown = false; changeShuttersLevel(STATE_DOWN); } //state = DOWN; //sendState(); } oldValueDown = value; /* debouncerStop.update(); value = debouncerStop.read(); if (value == 0 && value != oldValueStop) { shuttersHalt(); //state = IDLE; //sendState(); } oldValueStop = value; */ if(currentShutterLevel != 100) { calibrateUp = false; calibratedUp = false; } if(currentShutterLevel != 0) { calibrateDown = false; calibratedDown = false; } if (isMoving) { unsigned long _now = millis(); if (_now - lastLevelTime >= timeOneLevel * 1000) { if (directionUpDown == DIRECTION_UP) { currentShutterLevel += 1; } else { currentShutterLevel -= 1; } currentShutterLevel = constrain(currentShutterLevel, 0, 100); #ifdef MY_DEBUG Serial.println(String(requestedShutterLevel)); Serial.println(String(currentShutterLevel)); #endif lastLevelTime = millis(); send(msgPercentage.set(currentShutterLevel)); } if (currentShutterLevel == requestedShutterLevel) { if(currentShutterLevel == 0 && !calibratedDown) { if(calibrateDown == false) { calibrateDown = true; calibratedDown = false; calibrationStartTime = _now; } else { if(calibratedDown == false) { if (_now - calibrationStartTime >= calibrationTime * 1000) { calibratedDown = true; } } } } else if (currentShutterLevel == 100 && !calibratedUp) { if(calibrateUp == false) { calibrateUp = true; calibratedUp = false; calibrationStartTime = _now; } else { if(calibratedUp == false) { if (_now - calibrationStartTime >= calibrationTime * 1000) { calibratedUp = true; } } } } else { shuttersHalt(); } } } else { if (requestedShutterLevel != currentShutterLevel) { if (requestedShutterLevel > currentShutterLevel) { shuttersUp(); } else { shuttersDown(); } lastLevelTime = millis(); } } }
    • pepson

      New version MySensors 2.3.0 with RFM69HW - Problem
      Home Assistant • • pepson  

      5
      0
      Votes
      5
      Posts
      1842
      Views

      Andrew Maynard

      did you figure this out? i keep getting errors trying to declare mhz
    • pepson

      Build gateway 2.0.0 on rpi3
      Troubleshooting • • pepson  

      6
      0
      Votes
      6
      Posts
      901
      Views

      mfalkvidd

      (check out 2.2.0, modify the version number in core/Version.h, configure and make and see if that fools Home Assistant)
    • pepson

      Support MySensors 2.2.0 in Home Assistant
      Home Assistant • • pepson  

      3
      0
      Votes
      3
      Posts
      1493
      Views

      pepson

      But control switch relay not woking on my MySensors 2.2.0... I describve it in other topic: link text
    • pepson

      MySensors ethernet 2.2.0 problem with control node switches
      Home Assistant • • pepson  

      12
      0
      Votes
      12
      Posts
      2388
      Views

      pepson

      @gohan said in MySensors ethernet 2.2.0 problem with control node switches: send(msg.set(RELAY_OFF), false); // notify controller to show off state ok looks that is ok but please give me a time i test it more.
    • pepson

      RFM69HW in MySensors 2.2.0
      Development • • pepson  

      2
      0
      Votes
      2
      Posts
      497
      Views

      JohnRob

      I had asked the same question but before V2.2.0 See this post: RFM69
    • pepson

      Gateway all in one
      Hardware • • pepson  

      13
      0
      Votes
      13
      Posts
      3108
      Views

      scalz

      For the moment, the lib doesn't support multiple transport (rfm69, rs485 etc.) at same time. Also, important side not, i don't think a Nano is enough powerful for doing this, flash nor ram..maybe i'm wrong
    • pepson

      Add support button inclusion
      Domoticz • • pepson  

      1
      0
      Votes
      1
      Posts
      911
      Views

      No one has replied

    • pepson

      send updates regularly in noides HOW ?
      General Discussion • • pepson  

      5
      0
      Votes
      5
      Posts
      1397
      Views

      pepson

      I dont understand and i am begginer. Can you explaine me more and give me ready solution please ? This is my actual sketch which i use: /** DESCRIPTION Sketch for 2x relay with buttons monostable. After back power all relays set OFF and send correct status OFF to controller. */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enabled repeater feature for this node #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> // Define Relays #define RELAY_ON 1 // GPIO value to write to turn on attached relay #define RELAY_OFF 0 // GPIO value to write to turn off attached relay // Define Sensor ID's #define SSR_A_ID 1 // Id of the sensor child #define SSR_B_ID 2 // Id of the sensor child // Define buttons and relays const int buttonPinA = 3; const int buttonPinB = 4; const int relayPinA = 5; const int relayPinB = 6; // Define Variables int oldValueA = 0; int oldValueB = 0; bool stateA = false; bool stateB = false; int trigger = 0; Bounce debouncerA = Bounce(); Bounce debouncerB = Bounce(); MyMessage msgA(SSR_A_ID, V_STATUS); MyMessage msgB(SSR_B_ID, V_STATUS); void setup() { pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up // After setting up the buttons, setup debouncer debouncerA.attach(buttonPinA); debouncerA.interval(5); debouncerB.attach(buttonPinB); debouncerB.interval(5); // Make sure relays are off when starting up digitalWrite(relayPinA, RELAY_OFF); digitalWrite(relayPinB, RELAY_OFF); // Then set relay pins in output mode pinMode(relayPinA, OUTPUT); pinMode(relayPinB, OUTPUT); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("2xRelay with monostable", "1.0"); // Register all sensors to gw (they will be created as child devices) present(SSR_A_ID, S_LIGHT); present(SSR_B_ID, S_LIGHT); } /* Example on how to asynchronously check for new messages from gw */ void loop() { if (trigger == 0){ send(msgA.set(false)); // Send off state for relayA to ensure controller knows the switch is off send(msgB.set(false)); // Send off state for relayB to ensure controller knows the switch is off trigger = 1; } debouncerA.update(); // Get the update value int valueA = debouncerA.read(); if (valueA != oldValueA && valueA == 0) { send(msgA.set(stateA ? false : true), true); // Send new state and request ack back } oldValueA = valueA; debouncerB.update(); // Get the update value int valueB = debouncerB.read(); if (valueB != oldValueB && valueB == 0) { send(msgB.set(stateB ? false : true), true); // Send new state and request ack back } oldValueB = valueB; } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_STATUS) { switch (message.sensor) { case 1: stateA = message.getBool(); digitalWrite(message.sensor + 4, stateA ? RELAY_ON : RELAY_OFF); break; case 2: stateB = message.getBool(); digitalWrite(message.sensor + 4, stateB ? RELAY_ON : RELAY_OFF); break; } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.println(message.sensor); Serial.print("from node:"); Serial.println(message.sender); Serial.print(", New status: "); Serial.println(message.getBool()); } }```
    • pepson

      repeater feature-How it works ?
      General Discussion • • pepson  

      2
      0
      Votes
      2
      Posts
      1974
      Views

      mfalkvidd

      Start with https://www.mysensors.org/about/network and https://www.mysensors.org/download/sensor_api_20#create-repeating-nodes If you have further questions, just post them here and we'll try to answer.
    • pepson

      BMP085 + DHT22
      Development • • pepson  

      5
      0
      Votes
      5
      Posts
      2063
      Views

      DannyM

      @pepson I did what you tried to do, and it worked, also in Domoticz two temps are visible. This is my code: /** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Pressure sensor example using BMP085 module * http://www.mysensors.org/build/pressure * Toegevoegd: na 10x dezelfde waarde te hebben gelezen bij TeEmp en Hum toch een waarde aan de GW sturen. */ #include <SPI.h> #include <Wire.h> #include <DHT.h> #include <MySensor.h> #include <Adafruit_BMP085.h> static const uint8_t FORCE_UPDATE_N_READS = 10; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; #define BARO_CHILD 0 #define TEMP_CHILD 1 #define CHILD_ID_HUM 2 #define CHILD_ID_TEMP 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 const float ALTITUDE = 1.05; // <-- adapt this value to your own location's altitude. // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute. const unsigned long SLEEP_TIME = 60000; const char *weather[] = { "stabiel", "zonnig", "bewolkt", "onstabiel", "onweer", "onbekend" }; enum FORECAST { STABIEL = 0, // "Stable Weather Pattern" ZONNIG = 1, // "Slowly rising Good Weather", "Clear/Sunny " BEWOLKT = 2, // "Slowly falling L-Pressure ", "BEWOLKT/Rain " ONSTABIEL = 3, // "Quickly rising H-Press", "Not Stable" ONWEER = 4, // "Quickly falling L-Press", "ONWEER" ONBEKEND = 5 // "ONBEKEND (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor MySensor gw; float lastPressure = -1; float lastTempBMP = -1; int lastForecast = -1; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h be dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; DHT dht; float lastTempDHT; float lastHum; boolean metric = true; MyMessage tempMsg(TEMP_CHILD, V_TEMP); MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage forecastMsg(BARO_CHILD, V_FORECAST); MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("BaroHum", "2.0"); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } // Register sensors to gw (they will be created as child devices) gw.present(BARO_CHILD, S_BARO); gw.present(TEMP_CHILD, S_TEMP); gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; } void loop() { float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; float temperatureBMP = bmp.readTemperature(); if (metric) { // Convert to fahrenheit temperatureBMP = temperatureBMP * 9.0 / 5.0 + 32.0; } int forecast = sample(pressure); Serial.print("Temperature = "); Serial.print(temperatureBMP); Serial.println(metric ? " *C" : " *F"); Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); if (temperatureBMP != lastTempBMP) { gw.send(tempMsg.set(temperatureBMP, 1)); lastTempBMP = temperatureBMP; } if (pressure != lastPressure) { gw.send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { gw.send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } delay(dht.getMinimumSamplingPeriod()); float temperatureDHT = dht.getTemperature(); if (isnan(temperatureDHT)) { Serial.println("Failed reading temperature from DHT"); } else if (temperatureDHT != lastTempDHT || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { lastTempDHT = temperatureDHT; if (!metric) { temperatureDHT = dht.toFahrenheit(temperatureDHT); } nNoUpdatesTemp = 0; gw.send(msgTemp.set(temperatureDHT, 1)); Serial.print("T: "); Serial.println(temperatureDHT); } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { lastHum = humidity; nNoUpdatesHum = 0; gw.send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } else { // Increase no update counter if the temperature stayed the same nNoUpdatesHum++; } gw.sleep(SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = ONBEKEND; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = ONBEKEND; } else if (dP_dt < (-0.25)) { forecast = ONWEER; } else if (dP_dt > 0.25) { forecast = ONSTABIEL; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = BEWOLKT; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = ZONNIG; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABIEL; } else { forecast = ONBEKEND; } // uncomment when debugging //Serial.print(F("Forecast at minute ")); //Serial.print(minuteCount); //Serial.print(F(" dP/dt = ")); //Serial.print(dP_dt); //Serial.print(F("kPa/h --> ")); //Serial.println(weather[forecast]); return forecast; } /** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Pressure sensor example using BMP085 module * http://www.mysensors.org/build/pressure * Toegevoegd: na 10x dezelfde waarde te hebben gelezen bij TeEmp en Hum toch een waarde aan de GW sturen. */ #include <SPI.h> #include <Wire.h> #include <DHT.h> #include <MySensor.h> #include <Adafruit_BMP085.h> static const uint8_t FORCE_UPDATE_N_READS = 10; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; #define BARO_CHILD 0 #define TEMP_CHILD 1 #define CHILD_ID_HUM 2 #define CHILD_ID_TEMP 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 const float ALTITUDE = 1.05; // <-- adapt this value to your own location's altitude. // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute. const unsigned long SLEEP_TIME = 60000; const char *weather[] = { "stabiel", "zonnig", "bewolkt", "onstabiel", "onweer", "onbekend" }; enum FORECAST { STABIEL = 0, // "Stable Weather Pattern" ZONNIG = 1, // "Slowly rising Good Weather", "Clear/Sunny " BEWOLKT = 2, // "Slowly falling L-Pressure ", "BEWOLKT/Rain " ONSTABIEL = 3, // "Quickly rising H-Press", "Not Stable" ONWEER = 4, // "Quickly falling L-Press", "ONWEER" ONBEKEND = 5 // "ONBEKEND (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor MySensor gw; float lastPressure = -1; float lastTempBMP = -1; int lastForecast = -1; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h be dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; DHT dht; float lastTempDHT; float lastHum; boolean metric = true; MyMessage tempMsg(TEMP_CHILD, V_TEMP); MyMessage pressureMsg(BARO_CHILD, V_PRESSURE); MyMessage forecastMsg(BARO_CHILD, V_FORECAST); MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { gw.begin(); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("BaroHum", "2.0"); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } // Register sensors to gw (they will be created as child devices) gw.present(BARO_CHILD, S_BARO); gw.present(TEMP_CHILD, S_TEMP); gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; } void loop() { float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; float temperatureBMP = bmp.readTemperature(); if (metric) { // Convert to fahrenheit temperatureBMP = temperatureBMP * 9.0 / 5.0 + 32.0; } int forecast = sample(pressure); Serial.print("Temperature = "); Serial.print(temperatureBMP); Serial.println(metric ? " *C" : " *F"); Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); if (temperatureBMP != lastTempBMP) { gw.send(tempMsg.set(temperatureBMP, 1)); lastTempBMP = temperatureBMP; } if (pressure != lastPressure) { gw.send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { gw.send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } delay(dht.getMinimumSamplingPeriod()); float temperatureDHT = dht.getTemperature(); if (isnan(temperatureDHT)) { Serial.println("Failed reading temperature from DHT"); } else if (temperatureDHT != lastTempDHT || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { lastTempDHT = temperatureDHT; if (!metric) { temperatureDHT = dht.toFahrenheit(temperatureDHT); } nNoUpdatesTemp = 0; gw.send(msgTemp.set(temperatureDHT, 1)); Serial.print("T: "); Serial.println(temperatureDHT); } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { lastHum = humidity; nNoUpdatesHum = 0; gw.send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } else { // Increase no update counter if the temperature stayed the same nNoUpdatesHum++; } gw.sleep(SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = ONBEKEND; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = ONBEKEND; } else if (dP_dt < (-0.25)) { forecast = ONWEER; } else if (dP_dt > 0.25) { forecast = ONSTABIEL; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = BEWOLKT; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = ZONNIG; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABIEL; } else { forecast = ONBEKEND; } // uncomment when debugging //Serial.print(F("Forecast at minute ")); //Serial.print(minuteCount); //Serial.print(F(" dP/dt = ")); //Serial.print(dP_dt); //Serial.print(F("kPa/h --> ")); //Serial.println(weather[forecast]); return forecast; }
    • pepson

      Clear EEPROM - sketch after that not working-HELP
      Development • • pepson  

      3
      0
      Votes
      3
      Posts
      3808
      Views

      hek

      @pepson said: https://www.arduino.cc/en/Tutorial/EEPROMClear That sketch initialises EEPROm to zeroes which isn't the factory value, 0xff. Use the MySensors provided sketch instead: https://www.mysensors.org/build/debug#clearing-eeprom
    • pepson

      Case printer 3D - Mysensors Gateway
      Enclosures / 3D Printing • • pepson  

      3
      0
      Votes
      3
      Posts
      1809
      Views

      Martin Tellblom

      @pepson said: roject for case printer 3D for MySensors Gateway on PCB OSHpark with arduino nano ? I need case for it... As this: https://forum.mysensors.org/topic/56/arduino-nano-gateway-for-vera-pcb-link/2 If you have a own printer it's easy to do a case using Tinkercad and it's free to use