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!
  • RaspberryPi 4 as a gateway/controller

    4
    5
    1 Votes
    4 Posts
    85 Views
    R
    I bought second arduino uno. And, first Arduino has example MotionSensorRS485, second Arduino has example GetwaySerialRS485. And i have got the same situation. So even Gateway on Arduino doesn't see MotionSensor. Next test i made, i disconnected MAX485 converters, and i connected UART pins from first arduino to the second one (UART = Rx(8) <-> Tx(9), Tx(9)<->Rx(8)) and GND. And i have got the same result. Gateway doesn't see sensor.
  • Low Power LED detection : Voltage Divider or RC Time?

    3
    1
    0 Votes
    3 Posts
    35 Views
    skywatchS
    @Puneit-Thukral A photo-transistor maybe better as it will draw less current in 'off' mode. Google phototransistor applications and there will be another learning opportunity for you ;)
  • Error when trying to use another library with mysensors

    4
    0 Votes
    4 Posts
    271 Views
    SebexS
    @krabbi I have a similar issue as un4 described. When nWake is connected on GND it works fine, when connecting to D3 (6) it stops working. I'm using the same sketch source as krabbi. Any suggestions?
  • Merge Help: Door+ BME280

    3
    0 Votes
    3 Posts
    56 Views
    rvendrameR
    @Puneit-Thukral I have a similar sensor ( PIR + BMP280 + other stuff). I don't use smartSleep ( Since this code is old, only sleep was available ) so I can't speak about the sleep part. Maybe you could try with regular sleep just to see if brings some diference... Regarding the BME280 (BMP in my case) , I didn't have to use the Wire.begin() / end(), and I use the same library as yours (Adafruit). Code is bellow, in case you want to compare yourself. /** * 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 * (adopted from 5in1 V2.1) * Version 3.0 - RV - Shifted to BMP280 sensor, added pressure and water leakage (via ROPE https://www.amazon.com/gp/product/B004FTFQ4W/ref=ppx_od_dt_b_asin_title_s01?ie=UTF8&psc=1 ) * * * DESCRIPTION * BMP280 on std SDA/SDL pins (Temp/Pressure) * LDR on pin A1: GND ---> 10k ---> A1 <-- LDR <-- Vcc * PIR on D3 and wakeup via interrupt (in case of PIR trigger) * Smoke on D2 with interrupt wake up too. ( 4n25 4K7 on buzzer, 2M7 Pullup resistor recommended ) * Water Sensing cable on A2: GND --> 100k --> A2 <-- X--X <-- Vcc * (https://www.amazon.com/gp/product/B004FTFQ4W/ref=ppx_od_dt_b_asin_title_s01?ie=UTF8&psc=1) * * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below) * */ // Enable debug prints to serial monitor #define MY_DEBUG // Board type #define DRAGON // PRO_MINI // DRAGON / SENSEBENDER // Define a static node address, AUTO or 1-255 fixed #define MY_NODE_ID 25 // AUTO #define MY_PARENT_NODE_ID AUTO // Enable and select radio type attached #define MY_RADIO_RF24 // MY_RADIO_RFM69 // Uncomment the line below, to transmit battery voltage as a normal sensor value #define BATT_SENSOR 199 #define NAME "8in1 Sensor" #define RELEASE "3.3" // Pin definitions for sensors #define SDA_PIN A5 // Just to document std IC2 interface #define SCL_PIN A4 // Just to document std IC2 interface #define LDR_PIN A1 // Analog Light sensor (LDR) #define WATER_PIN A2 // Analog Water Leak sensor (rope) #define SMOKE_PIN 2 // Digital Smoke sensor (0/1) #define PIR_PIN 3 // PIR Sensor (0/1) #define TRIGGER_PIN 4 // Trigger for HC-SR04 sensor #define ECHO_PIN 5 // Echo for HC-SR04 sensor #ifdef DRAGON // #define SPIFLASH_PIN 8 #define LED_PIN 9 #define TEST_PIN A0 #define MY_RF24_CE_PIN 7 #define MY_RF24_CS_PIN 10 // #define MY_SOFTSPI // #define MY_SOFT_SPI_SCK_PIN 13 // #define MY_SOFT_SPI_MISO_PIN 12 // #define MY_SOFT_SPI_MOSI_PIN 11 #endif #ifdef SENSEBENDER #define SPIFLASH_PIN 8 #define TEST_PIN A0 #define OTA_ENABLE A1 #define LED_PIN A2 #define ATSHA204_PIN 17 // A3 #endif #ifdef PRO_MINI #define LED_PIN 8 #endif // Includes /////////////////////////////////////////// #include <SPIMemory.h> #include <SPI.h> #include <MySensors.h> //#include <Wire.h> //#include <EEPROM.h> //#include <sha204_library.h> //#include <Adafruit_Sensor.h> #include <Adafruit_BMP280.h> /// Sketch parameters SETUP //////////////////////////// // Child sensor ID's #define CHILD_ID_TEMP 1 #define CHILD_ID_HUM 2 #define CHILD_ID_PRESS 3 #define CHILD_ID_LIGHT 4 #define CHILD_ID_PIR 5 #define CHILD_ID_SMOKE 6 #define CHILD_ID_WATER 7 #define CHILD_ID_TANK 8 // How many milli seconds should we wait for OTA? #define OTA_WAIT_PERIOD 500 // How many milli seconds between each measurement #define MEASURE_INTERVAL 720000 // 12min // How many wakeups to send battery level #define BAT_INTERVAL 100 // around 20 hours // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 10 // around 2 hours // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes. // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 5 #define TEMP_TRANSMIT_THRESHOLD 0.5 #define LIGHT_TRANSMIT_THRESHOLD 5 #define PRESS_TRANSMIT_THRESHOLD 50 // Flash memory #ifdef SPIFLASH_PIN SPIFlash flash( SPIFLASH_PIN ); #endif // ATSHA204 #ifdef ATSHA204_PIN atsha204Class sha204( ATSHA204_PIN ); #endif //Weather Sensor BMP280 on IC2 (Temp/Hum/Pressure): #ifdef SDA_PIN and SCL_PIN Adafruit_BMP280 weather_sensor; #endif // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgPressure(CHILD_ID_PRESS, V_PRESSURE ); MyMessage msgLight(CHILD_ID_LIGHT, V_LIGHT_LEVEL); MyMessage msgMotion(CHILD_ID_PIR, V_TRIPPED); MyMessage msgSmoke(CHILD_ID_SMOKE, V_TRIPPED ); MyMessage msgWater(CHILD_ID_WATER, V_TRIPPED ); MyMessage msgDist(CHILD_ID_TANK, V_DISTANCE ); #ifdef BATT_SENSOR MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE); #endif // Global settings int measureCount; int sendBattery; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; float lastHumidity = -100; float lastPressure = -100; long lastBattery = -100; int lastPir = -1; int lastLight = -100; int lastSmoke = -1; int lastWater = -1; int lastDist = -1; /**************************************************** * * Setup code * ****************************************************/ void setup() { #ifdef LED_PIN pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH); #endif Serial.begin( MY_BAUD_RATE ); // Default for MySensors is 115200 // Test Mode ////////////////////////// #ifdef TEST_PIN pinMode(TEST_PIN,INPUT_PULLUP); if (!digitalRead(TEST_PIN)) testMode(); pinMode(TEST_PIN,INPUT); #endif // Pin Mode Setup ////////////////////// #ifdef BAT_PIN pinMode(BAT_PIN , INPUT); // Ext. Batery meter (1M / 470K resistors) #endif #ifdef SMOKE_PIN pinMode(SMOKE_PIN , INPUT ); #endif #ifdef PIR_PIN pinMode(PIR_PIN , INPUT); #endif #ifdef TRIGGER_PIN pinMode(PIR_PIN , OUTPUT); #endif #ifdef ECHO_PIN pinMode(ECHO_PIN , INPUT); #endif // Startup Info Serial.print("Board:"); Serial.print( ARDUINO ); Serial.print( "\t" ); Serial.print( F_CPU / 1000000 ); Serial.print(" Mhz\t"); Serial.print( NAME ); Serial.print(" "); Serial.println( RELEASE ); Serial.print("Nrf24 CE/CS:"); Serial.print( MY_RF24_CE_PIN); Serial.print("/"); Serial.print( MY_RF24_CS_PIN ); Serial.print("\tNODE ID:"); Serial.print(hwReadConfig(EEPROM_NODE_ID_ADDRESS)); isMetric = getControllerConfig().isMetric; Serial.print(F("\tisMetric:")); Serial.println(isMetric); #ifdef OTA_WAIT_PERIOD Serial.print("OTA FW Enabled"); #endif // SPI Flash #ifdef SPIFLASH_PIN SPI.begin(); Serial.print(F("\tFlash:")); if ( flash.begin() ) { Serial.print( flash.getCapacity() / 8000 , 0 ); Serial.print( "KB"); flash.powerDown(); } else Serial.print( flash.error(VERBOSE) ); #endif // BMP280 init //////////////////////// #ifdef SDA_PIN and SCL_PIN Serial.print(F("\tBMP280:")); if ( weather_sensor.begin() ) { Serial.print(F("OK")); /* Default settings from datasheet. */ weather_sensor.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ Adafruit_BMP280::SAMPLING_X1, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X1, /* Pressure oversampling */ Adafruit_BMP280::FILTER_OFF ); /* Filtering. */ } else Serial.print(F("ERROR!")); #endif // Force 1st transmission of all sensors measureCount = FORCE_TRANSMIT_INTERVAL; sendBattery = BAT_INTERVAL; #ifdef LED_PIN digitalWrite(LED_PIN, LOW); #endif Serial.println(F("\n///////////////////// ONLINE /////////////////////")); Serial.flush(); } void presentation() { sendSketchInfo( NAME , RELEASE); #ifdef SDA_PIN present(CHILD_ID_TEMP,S_TEMP); present(CHILD_ID_HUM,S_HUM); present(CHILD_ID_PRESS, S_BARO ); #endif #ifdef LDR_PIN present(CHILD_ID_LIGHT,S_LIGHT_LEVEL); #endif #ifdef PIR_PIN present(CHILD_ID_PIR,S_MOTION); #endif #ifdef SMOKE_PIN present(CHILD_ID_SMOKE, S_SMOKE); #endif #ifdef WATER_PIN present(CHILD_ID_WATER, S_WATER_LEAK ); #endif #ifdef TRIGER_PIN present(CHILD_ID_TANK, S_DISTANCE ); #endif #ifdef BATT_SENSOR present(BATT_SENSOR, S_POWER); #endif } /*********************************************** * * Main loop function * ***********************************************/ void loop() { #ifdef LED_PIN digitalWrite( LED_PIN , HIGH ); #endif boolean forceTransmit = false; transmission_occured = false; if ( ++measureCount > FORCE_TRANSMIT_INTERVAL ) { // force a transmission forceTransmit = true; Serial.print(F("[Force Transmission]")); measureCount = 0; } // Light, PIR, Smoke, Water leak sendLight(forceTransmit); sendPir(forceTransmit); sendSmoke(forceTransmit); sendWater(forceTransmit); sendWeather(forceTransmit); sendDistance(forceTransmit); // Battery level report if ( ++sendBattery > BAT_INTERVAL ) { sendBattLevel(true); sendBattery = 0; } // Wait for FW update... if (transmission_occured) { wait(OTA_WAIT_PERIOD); measureCount = 0; } #ifdef LED_PIN digitalWrite( LED_PIN , LOW ); #endif Serial.println(); // Trick to avoid false triggering on PIR sleep(1000); // Sleep until interval or PIR or smoke trigger if ( lastSmoke == 1 ) // In case of Smoke Alarm, don't sleep too much... sleep( 45000 ); else if ( lastPir == 1 ) // In case of Motion, stop PIR detecting for 1 complete cycle... sleep( 0 , CHANGE , MEASURE_INTERVAL ); else sleep( 0 , CHANGE , 1 , CHANGE, MEASURE_INTERVAL); // Default: Wake up on any PIR and Smoke... // To avoid false Smoke alarm wait(100); // Wake Serial.print( millis() ); Serial.print("[WAKE]"); } /********************************************* * * Sends Motion status * *********************************************/ void sendDistance(bool force) { long duration; int distance; #ifdef TRIGER_PIN digitalWrite( TRIGER_PIN, LOW); delayMicroseconds(2); digitalWrite( TRIGER_PIN , HIGH); delayMicroseconds(10); digitalWrite( TRIGER_PIN , LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn( ECHO_PIN , HIGH); // Calculating the distance distance = duration * 0.034 / 2; if ( distance != lastDist || force ) { Serial.print(" D:");Serial.print(distance); send(msgDist.set(distance)); transmission_occured = true; lastDist = distance; } #endif } /********************************************* * * Sends Motion status * *********************************************/ void sendPir(bool force) { #ifdef PIR_PIN int currPir = digitalRead( PIR_PIN ); if ( lastPir != currPir || force ) { Serial.print(" M:");Serial.print(currPir); send(msgMotion.set(currPir)); transmission_occured = true; lastPir = currPir; } #endif } /********************************************* * * Sends Smoke status * *********************************************/ void sendSmoke(bool force) { #ifdef SMOKE_PIN int currSmoke = !digitalRead( SMOKE_PIN ); // Low = Smoke Triggered if ( lastSmoke != currSmoke || force ) { Serial.print(" S:");Serial.print(currSmoke); send(msgSmoke.set(currSmoke)); transmission_occured = true; lastSmoke = currSmoke; } #endif } /********************************************* * * Sends Smoke status * *********************************************/ void sendWater(bool force) { #ifdef WATER_PIN int currWater = ( analogRead( WATER_PIN ) > 500 ? 1 : 0 ) ; //Serial.println( analogRead( WATER_PIN ) ); if ( lastWater != currWater || force ) { Serial.print(" W:");Serial.print(currWater); send(msgWater.set(currWater)); transmission_occured = true; lastWater = currWater; } #endif } /********************************************* * * Sends Light Level based on LDR * * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) * *********************************************/ void sendLight(bool force) { #ifdef LDR_PIN int currLight = map( analogRead( LDR_PIN ) , 0, 1024 , 0 , 100 ); int diffLight = abs( lastLight - currLight ); if (isnan(diffLight) || diffLight >= LIGHT_TRANSMIT_THRESHOLD || force ) { Serial.print(" L:");Serial.print(currLight); send(msgLight.set(currLight)); lastLight = currLight; transmission_occured = true; } #endif } /********************************************* * * Sends temperature and humidity from Si7021 sensor * * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) * *********************************************/ void sendWeather(bool force) { #ifdef SDA_PIN and SCL_PIN bool tx = force; // Sensor reading float temp = weather_sensor.readTemperature(); //float humd = "N/A" ; // Hum is not supported on BMP280 (But it is in BME280) float pres = weather_sensor.readPressure(); // Temperature delta float diffTemp = abs( lastTemperature - temp ); if (diffTemp >= TEMP_TRANSMIT_THRESHOLD) tx = true; // Humidity delta //float diffHum = abs( lastHumidity - humd ); //if ( isnan(diffHum) || diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true; // Pressure delta float diffPress = abs( lastPressure - pres ); if (diffPress >= PRESS_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; Serial.print(" T:");Serial.print(temp,1); //Serial.print(" H:");Serial.print(humd,1); Serial.print(" P:");Serial.print(pres,1); send(msgTemp.set(temp,1)); //send(msgHum.set(humd,1)); send(msgPressure.set(pres,1)); lastTemperature = temp; //lastHumidity = humd; lastPressure = pres; transmission_occured = true; } // BUG? High consumption ... //digitalWrite( SDA_PIN , LOW ); //digitalWrite( SCL_PIN , LOW ); #endif } /******************************************** * * Sends battery information (battery percentage) * * Parameters * - force : Forces transmission of a value * *******************************************/ void sendBattLevel(bool force) { #ifdef BAT_PIN long vcc = ( analogRead( BAT_PIN ) * 3300.0 / 1024.0 ) * 3.13; #else long vcc = readVcc(); #endif if ( abs( ( vcc - lastBattery ) ) > 100 || force) { lastBattery = vcc; #ifdef BATT_SENSOR float send_voltage = float(vcc)/1000.0f; send(msgBatt.set(send_voltage,3)); #endif // Calculate percentage vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at long percent = vcc / 13.0; //long percent = constrain( map( vcc, 4000 , 9000, 0, 100 ) , 0 , 100 ); Serial.print(" Batt%:"); Serial.print( percent ); sendBatteryLevel(percent); transmission_occured = true; } } /******************************************* * * Internal battery ADC measuring * *******************************************/ long readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADcdMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } /**************************************************** * * Verify all peripherals, and signal via the LED if any problems. * ****************************************************/ void testMode() { uint8_t rx_buffer[SHA204_RSP_SIZE_MAX]; uint8_t ret_code; boolean fail = false; #ifdef LED_PIN digitalWrite(LED_PIN, HIGH); // Turn on LED. #endif Serial.println(F(" - TestMode")); Serial.println(F("Testing peripherals!")); Serial.flush(); #ifdef SDA_PIN Serial.print(F(" IC2 weather sensor ")); Serial.flush(); if ( weather_sensor.begin() && weather_sensor.readPressure() && weather_sensor.readTemperature() > 900 ) { Serial.println(F("ok!")); } else { Serial.println(F("failed!")); fail = true; } Serial.flush(); #endif #ifdef SPIFLASH_PIN Serial.print(F("-> Flash : ")); Serial.flush(); if (flash.begin()) { Serial.println(F("ok!")); } else { Serial.println(F("failed!")); fail = true; } Serial.flush(); #endif #ifdef ATSHA204_PIN Serial.print(F("-> SHA204 : ")); ret_code = sha204.sha204c_wakeup(rx_buffer); Serial.flush(); if (ret_code != SHA204_SUCCESS) { Serial.print(F("Failed to wake device. Response: ")); Serial.println(ret_code, HEX); } Serial.flush(); if (ret_code == SHA204_SUCCESS) { ret_code = sha204.getSerialNumber(rx_buffer); if (ret_code != SHA204_SUCCESS) { Serial.print(F("Failed to obtain device serial number. Response: ")); Serial.println(ret_code, HEX); fail = true; } else { Serial.print(F("Ok (serial : ")); for (int i=0; i<9; i++) { if (rx_buffer[i] < 0x10) Serial.print('0'); // Because Serial.print does not 0-pad HEX Serial.print(rx_buffer[i], HEX); } Serial.println(")"); } } Serial.flush(); #endif Serial.println(F("Test finished")); if ( !fail ) { Serial.println(F("Selftest ok!")); while (1) // Blink OK pattern! { #ifdef LED_PIN digitalWrite(LED_PIN, HIGH); delay(200); digitalWrite(LED_PIN, LOW); delay(200); #endif } } else { Serial.println(F("----> Selftest failed!")); while (1) // Blink FAILED pattern! Rappidly blinking.. { } } }
  • Question how to print MySensor message

    5
    0 Votes
    5 Posts
    27 Views
    mfalkviddM
    Maybe you can fill a global char array from within receive()? You’d have to handle quick successive calls in a good manner though.
  • Sniffing RS485 MODBUS data

    1
    2
    0 Votes
    1 Posts
    25 Views
    No one has replied
  • Dimmer sketches - array and multiple PWM led pins

    15
    1
    0 Votes
    15 Posts
    4k Views
    G
    Did someone got the idea why 100% in Domoticz is 99% in MySensors? Is MySensors limiting dimmer to 99% or is this caused by Domoticz?
  • Serial Gateway not connecting - ttyUSB0 in use

    30
    0 Votes
    30 Posts
    141 Views
    C
    And so here is my serial gateway with 3d printed case: [image: 1586636945529-20200411_212514.jpg]
  • Can ethernet gateway also publish everything to MQTT?

    5
    0 Votes
    5 Posts
    44 Views
    T
    @electrik Looks like the discovery does work with MQTT gateway. Thanks a bunch, I got it working now
  • How to workaround a dead Gateway.

    3
    0 Votes
    3 Posts
    36 Views
    R
    Thanks for the quick reply. I'll have a look.
  • not understanding Smart Sleep

    smartsleep sleep api
    6
    0 Votes
    6 Posts
    122 Views
    rejoe2R
    @Stef9998 said in not understanding Smart Sleep: @rejoe2 I'm in the process of configuring an OpenHab instance, and the binding should support smart sleep Don't know about OH's abilities, I "just" did the FHEM implementation of that feature :grinning: . That I don't understand. Why should the controller have queued messages when the node is sending the second type (going to sleep). The controller knows the node is awake (cause of first/awake message), so why should it start to queue them? It should just send them, and then when the controller knows, that a node will be asleep (second message) start queueing. The user or some automatics could create some message to be sent out at any point in time. But sending out any message only makes sense when the controller knows the node is actually listening - these are sparse blinks in time, so most of the time a message will be queued first (or let's call it retained to stick to mqtt conventions). Then the controller has to wait for a signal from the node side, but as described earlier, this should not be the "awake" message (meaning a sensor can deliver some values and so on), but the "will go to sleep" one (meaning: "I will stop talking now, but continue to listen for 500 ms now"). Hope the fog is clearing now...
  • Sleep - Sensor Data Interval

    2
    0 Votes
    2 Posts
    38 Views
    mfalkviddM
    Welcome to the forum @DCEM ! https://forum.mysensors.org/post/78795 describes one way to do it. The node requests the value of a parameter from the controller, and sleeps for that amount of time. See https://www.mysensors.org/download/sensor_api_20#requesting-data for documentation on how to request values
  • Problem with battery powered temperature sensor

    12
    0 Votes
    12 Posts
    1k Views
    W
    @olka Can't say I remember what I did anymore. Probably suppressed sending in the case of 85 degrees.
  • Sketch for Lightning Sensor

    58
    0 Votes
    58 Posts
    32k Views
    K
    Embedded Adventures is a fake website anymore. They don't send the mod-1016 sensor. The website still gets payment for products but there is no shipment. embedded adventures is fraudulent.
  • How can one use MyMessage class in library?

    5
    0 Votes
    5 Posts
    87 Views
    M
    @matkor said in How can one use MyMessage class in library?: Switching both clashing functions ( wakeUp1(), wakeUp2() ) to static functions seems to fix linking for me. This sees to be deadend as there come more function name clashes, and i suspect linking problems come from magic done by arduino IDE. Current hack for me is include in arduino sketch my lib headers after including MySensors: #include <MySensors.h> #include <MyLib.h> and than inside library use only: #include <core/MySensorsCore.h> not sure if its right solution, if one has any better please share.
  • isAck(): differentiation between sent and received messages

    5
    1 Votes
    5 Posts
    98 Views
    F
    The approach to differentiate the message did not work for my purpose: commands sent from Fhem are a set message requests return as set message Status message of the node (set message) returns as set message with Ack I.e. all are set messages (no differentiation possible) Because I use a counter to limit the resending of the status message from the node I used this counter to get to the destination. In short: If the reception was successful the counter goes to 0, the request to <0 and the send to >0. Here is my sketch, it is for switching several time controlled relays, for clarity I have removed the debug messages: /** * 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-2018 Sensnology AB * Full contributor list: https://github.com/mysensors/MySensors/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. * ******************************* * * DESCRIPTION * The RS485 Gateway prints data received from sensors on the serial link. * The gateway accepts input on seral which will be sent out on * the RS485 link. * * Wire connections (OPTIONAL): * - Inclusion button should be connected between digital pin 3 and GND * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series * * LEDs (OPTIONAL): * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or receive crc error * * If your Arduino board has additional serial ports * you can use to connect the RS485 module. * Otherwise, the gateway uses AltSoftSerial to handle two serial * links on one Arduino. Use the following pins for RS485 link * * Board Transmit Receive PWM Unusable * ----- -------- ------- ------------ * Teensy 3.0 & 3.1 21 20 22 * Teensy 2.0 9 10 (none) * Teensy++ 2.0 25 4 26, 27 * Arduino Uno 9 8 10 * Arduino Leonardo 5 13 (none) * Arduino Mega 46 48 44, 45 * Wiring-S 5 6 4 * Sanguino 13 14 12 * */ #define SN "MultiTimerRelay" #define SV "1.0" // Enable debug prints to serial monitor #define MY_DEBUG // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin //#define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 19200 // Enable this if RS485 is connected to a hardware serial port #define MY_RS485_HWSERIAL Serial #define MY_NODE_ID 2 // Id of the Node #define MY_TRANSPORT_WAIT_READY_MS 30000 //loop is beginning at 3000ms whitout connection #include <MySensors.h> //++++++++ Relays +++++++++ #define RELAY_ON 1 // switch around for ACTIVE LOW / ACTIVE HIGH relay #define RELAY_OFF 0 #define noRelays 3 // min 2 const int relayPin[] = {7, 8, 9}; // switch around pins to your desire uint32_t relayTime[] = {0, 0, 0}; // on time for Relay to set from Fhem volatile uint32_t startTime[] = {0, 0, 0}; // time to switch Relay on int relayAckCountR[noRelays]; // ACK retry counter relay int relayAckCountT[noRelays]; // ACK retry counter time const uint32_t timeFactor = 1000UL; // to send minutes = 60000UL or seconds = 1000UL; UL says compiler is unsigned long!!! class Relay // relay class, store all relevant data (equivalent to struct) { public: int relayPin; // physical pin number of relay boolean relayState; // relay status (also stored in EEPROM) uint32_t relayTime; // on time for Relay uint32_t startTime; // time to switch Relay on int relayAckCountR; // ACK retry counter relay int relayAckCountT; // ACK retry counter time }; Relay Relays[noRelays]; MyMessage msgRelay[noRelays]; MyMessage msgTime[noRelays]; void before() { } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); //++++++++ Relays +++++++++ for (int i = 0; i < noRelays; i++) { present(i, S_DIMMER); // present sensor to gateway wait(20); } } void setup() { //++++++++ Relays +++++++++ for (int i = 0; i < noRelays; i++) { Relays[i].relayPin = relayPin[i]; // assign physical pins Relays[i].startTime = startTime[i]; // assign time to switch relay on Relays[i].relayTime = relayTime[i]; // assign time for relay on msgRelay[i].sensor = i; // initialize messages msgRelay[i].type = V_STATUS; msgTime[i].sensor = i; msgTime[i].type = V_PERCENTAGE; pinMode(Relays[i].relayPin, OUTPUT); Relays[i].relayState = RELAY_OFF; // set all relaysState off digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // write all relays off //send(msgRelay[i].set(Relays[i].relayState ? true : false)); wait(20); } for (int i = 0; i < noRelays; i++) { request(i, V_STATUS); // Set relay to last known state Relays[i].relayAckCountR = -1; // for the control of the request wait(100); request(i, V_PERCENTAGE); // Set relay to last known state Relays[i].relayAckCountT = -1; // for the control of the request wait(100); } } void loop() { //++++++++ Relays +++++++++ uint32_t currentTime = millis(); //Zeitsteuerung der Relays for (byte i = 0; i < noRelays; i++) { if ( Relays[i].relayState == RELAY_ON && (currentTime - Relays[i].startTime > Relays[i].relayTime)) { digitalWrite(Relays[i].relayPin, !Relays[i].relayState ? RELAY_ON : RELAY_OFF); Relays[i].relayState = !Relays[i].relayState; send(msgRelay[i].set(Relays[i].relayState ? true : false), true); // Send value to gw with ACK Relays[i].relayTime = 0; Relays[i].relayAckCountR = 3; wait(100); send(msgTime[i].set(Relays[i].relayTime), true); // Send value to gw with ACK Relays[i].relayAckCountT = 3; wait(100); } } for (int i = 0; i < noRelays; i++) { if (Relays[i].relayAckCountR < 0) { wait(200); request(i, V_STATUS); // Set relay to last known state Relays[i].relayAckCountR = 0; wait(100); } if (Relays[i].relayAckCountT < 0) { wait(200); request(i, V_PERCENTAGE); // Set relay to last known state Relays[i].relayAckCountT = 0; wait(100); } if (Relays[i].relayAckCountR > 0) { wait(200); send(msgRelay[i].set(Relays[i].relayState ? true : false), true); // Send value to gw with ACK wait(100); } if (Relays[i].relayAckCountT > 0) { wait(200); send(msgTime[i].set(Relays[i].relayTime), true); // Send value to gw with ACK wait(100); } } } void receive(const MyMessage &message) { //++++++++ Relays +++++++++ if (message.type == V_STATUS && Relays[message.sensor].relayAckCountR <= 0) { Relays[message.sensor].relayAckCountR = 0; if (message.sensor < noRelays) { // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] Relays[message.sensor].relayState = message.getBool(); digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly //saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number) } if (Relays[message.sensor].relayState == RELAY_ON) { Relays[message.sensor].startTime = millis(); } } else if (message.isAck() && message.type == V_STATUS && Relays[message.sensor].relayAckCountR > 0) { Relays[message.sensor].relayAckCountR = 0; } else if (!message.isAck() && message.type == V_STATUS && Relays[message.sensor].relayAckCountR > 0) { Relays[message.sensor].relayAckCountR--; } else if (message.type == V_PERCENTAGE && Relays[message.sensor].relayAckCountT <= 0) { if (message.sensor < noRelays) { // check if message is valid for relays..... previous line [[[ if (message.sensor <=noRelays){ ]]] Relays[message.sensor].relayTime = (message.getByte() * timeFactor); // calculate to millis } } else if (message.isAck() && message.type == V_PERCENTAGE && Relays[message.sensor].relayAckCountT > 0) { Relays[message.sensor].relayAckCountT = 0; } else if (!message.isAck() && message.type == V_PERCENTAGE && Relays[message.sensor].relayAckCountT > 0) { Relays[message.sensor].relayAckCountT --; } }
  • Changing NODE ID for sketch for existing NODE

    3
    0 Votes
    3 Posts
    24 Views
    mntlvrM
    Thanks skywatch but by running the latest NodeManager I did not have to change anything.
  • Discover network topology?

    13
    0 Votes
    13 Posts
    3k Views
    Y
    @darkhorse Hi! Did you eventually created a controller that draws a network topology? If yes, could you share it?
  • Expanding the size of an existing array?

    14
    0 Votes
    14 Posts
    120 Views
    electrikE
    I think - am not sure - because you only include mysensors.h, which is only a header file without cpp files.
  • Error ! nowhere to send

    3
    0 Votes
    3 Posts
    46 Views
    mntlvrM
    @tekka Had tried that before , so I was looking for the solution not by changing IDE but why did it fail, So I loaded Windows 10 Pro Workstation on a new drive booted from that drive and setup windows. Once windows was all configured I then installed exact same IDE and library as before and what do you know it worked just fine. Conclusion it was the OS that stopped Arduino IDE 1.8.4 not the IDE or the MySenors Library, and yes it took more time to trouble but now I know why and I don't have to guess. I have found that Windows 10 is very protective of it's self and once system becomes corrupt in the smallest of ways you can bet before long you will see in other applications things starting to "not work" like they use to when you first installed the OS. If I had the time or desire I would switch over to Linux but I am to heavily invested in Windows with my machines and software for now and have been using Windows ever since Windows 3.0 Hope this might help others that might be having similar problems for the MySensors library's to fail when they should not be failing.So check out every avenue before blaming MySensors or the IDE Thanks for reading my post Bob

14

Online

11.7k

Users

11.2k

Topics

113.0k

Posts