Skip to content

Development

Discuss Arduino programming, library tips, share example sketches and post your general programming questions.
1.5k Topics 13.5k Posts

Subcategories


  • 56 578
    56 Topics
    578 Posts
    HJ_SKH
    Hi2All! Surprising is here. After about 24hours I refresh HA and suddenly my motion sensor was integrated. There is also second entity > battery : 0 , have to look deeper into that for understanding. Need to change little in the sketch, because don't want every short time 'no movement' so only when there is motion and maybe once a hour indication sensor is alive. Meantime I found 3 other good threats: https://forum.mysensors.org/topic/11200/finally-progress-evidence-based-radio-testing-method-and-capacitors https://forum.mysensors.org/topic/1664/which-are-the-best-nrf24l01-modules/27 https://forum.mysensors.org/topic/9550/build-a-reliable-power-supply-chain Very usefull for me also finally progress because of lacking time in the past. Great jobs are done here! Thanks for this all of you guys or girls!
  • Help with a custom Mysensors Node

    2
    0 Votes
    2 Posts
    1k Views
    mfalkviddM
    Welcome to the MySensors forum @pesh000 ! After reading the getting started guide, you can start off with the relay example. When that works, add the other components. Doing all components at once will be hard and makes troubleshooting a mess.
  • Repeater questions

    5
    0 Votes
    5 Posts
    2k Views
    Tore André RosanderT
    @AWI The code is from the MySensors examples and i use it to control 3 mosfets that controls a ledstrip. I need the heartbeat because i use the RPi gateway with the NRF24 chip directly connected to the RPi, and the gateway software for the raspberry dont store the network map so if i reboot the RPi the nodes loose connection to the gateway.
  • Node sending same value multiple times, why?

    7
    0 Votes
    7 Posts
    1k Views
    Mark SwiftM
    I'll try a debug when I'm home, but this is a remote node using MYS firmware... See MYS screenshots here: http://postimg.org/gallery/8ynl0jw/c4dcd695/
  • WS2812B mysensors API 2.0 updated code, does anyone got it?

    1
    0 Votes
    1 Posts
    914 Views
    No one has replied
  • Signing_Soft in dev branch - How to do?

    24
    0 Votes
    24 Posts
    5k Views
    AnticimexA
    @Anduril :thumbsup:
  • 2.0b gateway - do I have to upgrade sensors/controller also?

    5
    0 Votes
    5 Posts
    1k Views
    tbowmoT
    @signal15 It's a new major release, that means that we could break compatibility with 1.x. It might work, but it also might not..
  • Problem with adding sonar sensor to another sketch

    10
    0 Votes
    10 Posts
    2k Views
    signal15S
    I upgraded the gateway to the 2.0b with the ESP8266OTA sketch. Problem solved. It does seem to work fine with the gateway on 2.0b, but sensors and controller on 1.5 code.
  • Status rading Node

    3
    0 Votes
    3 Posts
    1k Views
    marekdM
    @sundberg84 yes,yes,yes. Thanks! btw nice project :)
  • Newer RFM69 driver for 2.0b

    3
    0 Votes
    3 Posts
    1k Views
    K
    @lafleur I have also updated my local RFM69 library to the latest version with some additional changes to solve issues with acknowledgements not being received. If you're interested, you can see my conclusion here: https://forum.mysensors.org/topic/3663/testing-development-branch-with-rf69hw-is-not-working-as-it-should/12 I also link to a separate thread over at the low-power forum where things are discussed in more detail. If we are planning to upgrade the RFM library I propose that we include the fix I found. The only problem is that this fix is mostly a temporary solution, so perhaps it is better to wait until the issue is fixed in the library itself.
  • Direct Node to Node communications with Signing

    17
    0 Votes
    17 Posts
    3k Views
    AnticimexA
    @Mr.Osaka no worries. Thank you. Yes, the signing solution on development branch (which will be part of the next major release) is much easier to work with. Both with personalization, use and any maintenance required. It will also make node to node signing easier to initiate.
  • Bosch BMP280 Normal mode

    1
    0 Votes
    1 Posts
    859 Views
    No one has replied
  • 0 Votes
    6 Posts
    2k Views
    JoeridemanJ
    I have to admit TheoL I've spend some time looking and admiring your work. But I have not found your examples. I will look into the OTA programming, sounds great. My holiday is over, and the next one starts in july. This topic will probably sink down during this period ;-).
  • Local sensor (no radio)

    6
    0 Votes
    6 Posts
    4k Views
    hekH
    Sorry, haven't used Domoticz myself.
  • MyMessage entity number in stead of name

    mymessage otgw
    1
    0 Votes
    1 Posts
    690 Views
    No one has replied
  • Sensor ID Code display

    1
    1 Votes
    1 Posts
    655 Views
    No one has replied
  • RadioHead

    5
    0 Votes
    5 Posts
    1k Views
    hekH
    I don't think anyone have access to (or tried) a RFM95 radio among the core dev team.
  • RFM69 Driver

    1
    0 Votes
    1 Posts
    748 Views
    No one has replied
  • Over the Air Updates Guide?

    3
    0 Votes
    3 Posts
    2k Views
    m26872M
    @elmezie You've read through the http://forum.mysensors.org/topic/1914/over-the-air-ota-bootloading-update-tutorial ?
  • Is the dev branch better than 1.5?

    1
    0 Votes
    1 Posts
    640 Views
    No one has replied
  • Multiple I2C sensors sketch

    6
    0 Votes
    6 Posts
    4k Views
    TheoLT
    @macieiks I don't think you're question is really related to MySensors, it's more an Arduino related question. The problem you might have is the memory capacity of the Arduino. Here's the sketch for the first mySensor node I made. It uses an I2C lux and i2c barometric pressure sensor and an HDT11 humidity sensor. /** * 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 * This sketch provides an example how to implement a humidity/temperature * sensor using DHT11/DHT-22 * http://www.mysensors.org/build/humidity */ // #define DEBUG #include <SPI.h> #include <MySensor.h> #include <DHT.h> #include <Wire.h> #include <Adafruit_BMP085.h> #include <Adafruit_TSL2561_U.h> #include <Adafruit_Sensor.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_BARO 2 #define CHILD_ID_LIGHT 3 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 const float ALTITUDE = 28; // <-- adapt this value to your own location's altitude. Lijkt dus in meters te zijn unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds) const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" }; enum FORECAST { STABLE = 0, // "Stable Weather Pattern" SUNNY = 1, // "Slowly rising Good Weather", "Clear/Sunny " CLOUDY = 2, // "Slowly falling L-Pressure ", "Cloudy/Rain " UNSTABLE = 3, // "Quickly rising H-Press", "Not Stable" THUNDERSTORM = 4, // "Quickly falling L-Press", "Thunderstorm" UNKNOWN = 5 // "Unknown (More Time needed) }; Adafruit_BMP085 bmp = Adafruit_BMP085(); MySensor gw; Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); DHT dht; float lastTemp = -1000; float lastHum = -1; float lastPressure = -1; int lastForecast = -1; int lastLightLevel = -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; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage pressureMsg(CHILD_ID_BARO, V_PRESSURE); MyMessage forecastMsg(CHILD_ID_BARO, V_FORECAST); MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); /**************************************************************************/ /* Displays some basic information on this sensor from the unified sensor API sensor_t type (see Adafruit_Sensor for more information) */ /**************************************************************************/ #ifdef DEBUG void displaySensorDetails(void) { sensor_t sensor; tsl.getSensor(&sensor); Serial.println("------------------------------------"); Serial.print ("Sensor: "); Serial.println(sensor.name); Serial.print ("Driver Ver: "); Serial.println(sensor.version); Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux"); Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux"); Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux"); Serial.println("------------------------------------"); Serial.println(""); delay(500); } #endif /**************************************************************************/ /* Configures the gain and integration time for the TSL2561 */ /**************************************************************************/ void configureSensor(void) { /* You can also manually set the gain or enable auto-gain support */ // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */ // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */ tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */ /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */ tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */ // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */ // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */ /* Update these values depending on what you've set above! */ #ifdef DEBUG Serial.println("------------------------------------"); Serial.print ("Gain: "); Serial.println("Auto"); Serial.print ("Timing: "); Serial.println("13 ms"); Serial.println("------------------------------------"); #endif } void setup() { gw.begin(); #ifdef DEBUG Serial.begin(115200); Serial.println("Light Sensor Test"); Serial.println("115200"); #endif dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Inside weather conditions", "1.0"); /* Only presenting the sensors if they're available */ if (bmp.begin()) { gw.present(CHILD_ID_BARO, S_BARO); } #ifdef DEBUG else { Serial.println( 'Barometer not found' ); } #endif if(!tsl.begin()) { #ifdef DEBUG /* There was a problem detecting the ADXL345 ... check your connections */ Serial.print( "Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!" ); #endif // while(1); } else { #ifdef DEBUG /* Display some basic information on this sensor */ displaySensorDetails(); #endif /* Setup the sensor gain and integration time */ configureSensor(); gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); gw.sendBatteryLevel( 100 ); } void loop() { delay(dht.getMinimumSamplingPeriod()); float pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0; float temperature = bmp.readTemperature(); int forecast = sample(pressure); #ifdef DEBUG float dhtTemperature = dht.getTemperature(); Serial.print("Temperature = "); Serial.print(temperature); Serial.println( " *C" ); Serial.print("Pressure = "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Forecast = "); Serial.println(weather[forecast]); Serial.print( "Dht Temp: " ); Serial.print(dhtTemperature); Serial.println( " *C" ); #endif if (isnan(temperature)) { #ifdef DEBUG Serial.println("Failed reading temperature from DHT"); #endif } else if (temperature != lastTemp) { lastTemp = temperature; gw.send(msgTemp.set(temperature, 1)); #ifdef DEBUG Serial.print("T: "); Serial.println(temperature); #endif } float humidity = dht.getHumidity(); if (isnan(humidity)) { #ifdef DEBUG Serial.println("Failed reading humidity from DHT"); #endif } else if (humidity != lastHum) { lastHum = humidity; gw.send(msgHum.set(humidity, 1)); #ifdef DEBUG Serial.print("H: "); Serial.println(humidity); #endif } sensors_event_t event; // maybe a delay between the sensor readings tsl.getEvent(&event); /* Display the results (light is measured in lux) */ // if (event.light) { // removed test to see if we get a 0 meeting during the evening and night. #ifdef DEBUG Serial.print(event.light); Serial.println(" lux"); #endif if ( event.light != lastLightLevel ) { gw.send(lightMsg.set((uint16_t)event.light)); lastLightLevel = event.light; } /* } // removed test to see if we get a 0 meeting during the evening and night. else { // If event.light = 0 lux the sensor is probably saturated and no reliable data could be generated! #ifdef DEBUG Serial.println("Sensor overload"); #endif } */ if (pressure != lastPressure) { gw.send(pressureMsg.set(pressure, 0)); lastPressure = pressure; } if (forecast != lastForecast) { gw.send(forecastMsg.set(weather[forecast])); lastForecast = forecast; } gw.sleep(SLEEP_TIME); //sleep a bit } 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 = UNKNOWN; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = UNKNOWN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWN; } // uncomment when debugging #ifdef DEBUG 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]); #endif return forecast; }

16

Online

11.7k

Users

11.2k

Topics

113.0k

Posts