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!
  • MYSBootLoader OTA documentation

    5
    0 Votes
    5 Posts
    3k Views
    jsiddallJ
    @tekka, yes, sorry, should have clarified. 7 bytes for MYS sensor, but the 6 bytes I was referring to as a "header" was the typedef on the firmware download. So 7+6=13/32 leaving up to 19 bytes for the firmware block itself. Thanks for the clarification on the padding and the CRC. That will become important.
  • Multiple DH22 sensors

    7
    0 Votes
    7 Posts
    2k Views
    mfalkviddM
    @Jasper-van-Winden the wait has helped in many cases. Nobody is 100% sure why. Maybe it gives the capacitors and the power supply time to recover from the power used when sending. Maybe it is somethong else. But it often helps :)
  • Humidity+Relay with button node

    12
    0 Votes
    12 Posts
    3k Views
    theckoT
    @BartE Adding the extra code done the job, now its working great. Thank you for your help! The final working code if someone wonders is: #include <SPI.h> #include <MySensor.h> #include <DHT.h> #include <Bounce2.h> #include <MySigningNone.h> #include <MyTransportNRF24.h> #include <MyTransportRFM69.h> #include <MyHwATMega328.h> #define NODE_ID 1 #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define CHILD_ID_RELAY 2 #define RELAY_PIN 3 #define BUTTON_PIN 4 #define HUMIDITY_SENSOR_DIGITAL_PIN 2 //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) #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 MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW); MyHwATMega328 hw; MySensor gw(radio, hw); Bounce debouncer = Bounce(); int oldValue=0; bool state; MyMessage msg(CHILD_ID_RELAY,V_LIGHT); DHT dht; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { gw.begin(incomingMessage, AUTO, true); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); gw.sendSketchInfo("Combo", "1.0"); gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); pinMode(BUTTON_PIN,INPUT); digitalWrite(BUTTON_PIN,HIGH); debouncer.attach(BUTTON_PIN); debouncer.interval(5); gw.present(CHILD_ID_RELAY, S_LIGHT); metric = gw.getConfig().isMetric; digitalWrite(RELAY_PIN, RELAY_OFF); pinMode(RELAY_PIN, OUTPUT); state = gw.loadState(CHILD_ID_RELAY); digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF); } unsigned long lastCheckTimestamp = 0; // setup stuff void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { digitalWrite(RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF); gw.saveState(1, message.getBool()); Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } void loop() { gw.process(); if (debouncer.update() && debouncer.read() == 0) { gw.send(msg.set(gw.loadState(1)?false:true), true); // Send new state and request ack back } // Check if the minimal sample period has been passed if ((lastCheckTimestamp < (millis() - dht.getMinimumSamplingPeriod()) ) || lastCheckTimestamp > millis()) { lastCheckTimestamp = millis(); // do the normal stuff after the delay float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature != lastTemp) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } gw.send(msgTemp.set(temperature, 1)); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; gw.send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } } }
  • Powering a sensor with digital out

    27
    0 Votes
    27 Posts
    4k Views
    bjacobseB
    @xydix Arduino using Atmega can supply max 40mA per pin, and in total max 100mA. DS18B20 seems to use max 1,5mA so yes this will work After searching on the net. https://github.com/nathanchantrell/TinyTX/blob/master/TinyTX_DS18B20/TinyTX_DS18B20.ino The part for the power on, read, power off is below (taken from the above link): void loop() { digitalWrite(ONE_WIRE_POWER, HIGH); // turn DS18B20 sensor on //Sleepy::loseSomeTime(5); // Allow 5ms for the sensor to be ready delay(5); // The above doesn't seem to work for everyone (why?) sensors.begin(); //start up temp sensor sensors.requestTemperatures(); // Get the temperature tinytx.temp=(sensors.getTempCByIndex(0)*100); // Read first sensor and convert to integer, reversed at receiving end digitalWrite(ONE_WIRE_POWER, LOW); // turn DS18B20 off
  • request variable from gateway

    13
    0 Votes
    13 Posts
    8k Views
    cimba007C
    @jkandasa said: It is necessary in some cases, Smart-sleep recently added, before when node wake-up get some date(adjust sleep duration) from controller with request Yep .. but this would be even more useful if one node could query other nodes data and receive the resonse from the controller (if the other node is sleeping). Again .. my proposal is to differentiate between: Request data from controller (for any other node, including gateway) ( = history query of most recent update the controller knows about) Request data from destination node ( = live query ) Edit: I just discovered resource groups on mycontroller .. think this will help out a lot with my planned workaround ;-) Edit2: I could not help myself and request an improvement: https://github.com/mysensors/MySensors/issues/574
  • Conversion to mysensors 2.0 for BMP180

    8
    0 Votes
    8 Posts
    4k Views
    tlpeterT
    I just installed my own type of weather station with a BMP180 and the 2.0 sketch works fine. I think you are doing something wrong :smile:
  • 1 Votes
    14 Posts
    4k Views
    Daniel OliveiraD
    Hi! I accomplish to do what I wanted thanks to the help of you all, so I'm sharing the results :) I ended up with this very simple MySensorGeneric.ino that is able to manage a DHT and a BH1750 /** * Name: MySensorGeneric.ino * Created: 20-Aug-16 22:47:51 * Author: Daniel * ******************************* * * REVISION HISTORY * Version 0.1 - Development * */ #include "MySensorConfig.h" #include <MySensors.h> #include "MySensorWrapperDHT.h" #include "MySensorWrapperBH1750.h" #define CHILD_ID_LIGHT 2 #define CHILD_ID_TEMP 1 #define CHILD_ID_HUM 0 #define HUMIDITY_SENSOR_DIGITAL_PIN 3 MySensorWrapperBH1750 SensorBH1750(CHILD_ID_LIGHT); MySensorWrapperDHT SensorDHT(CHILD_ID_TEMP, CHILD_ID_HUM, HUMIDITY_SENSOR_DIGITAL_PIN); void setup() { SensorBH1750.Setup(); SensorDHT.Setup(); } void presentation() { sendSketchInfo("My Generic Sensor", "0.11"); SensorBH1750.Present(); SensorDHT.Present(); } void loop() { SensorBH1750.UpdateSensorValue(); SensorDHT.UpdateSensorValue(); wait(SLEEP_TIME); } I've created a class to manage the BH1750: MySensorWrapperBH1750.h // MySensorWrapperBH1750.h #ifndef _MYSENSORWRAPPERBH1750_h #define _MYSENSORWRAPPERBH1750_h //Need to add to project Version.h and MyEepromAdresses.h #include "MySensorsCore.h" #include <BH1750.h> class MySensorWrapperBH1750 { public: MySensorWrapperBH1750(uint8_t sensor_id); ~MySensorWrapperBH1750(); void Setup(); void Present(); void UpdateSensorValue(); private: uint8_t _sensor_id; uint16_t _lastValue; BH1750 _sensor; MyMessage _msg; }; #endif MySensorWrapperBH1750.cpp /** * Name: MySensorWrapperBH1750 * Created: 20-Aug-16 22:47:51 * Author: Daniel * Version 0.1 - Draft * ******************************* * * MySensors Wrapper for BH1750 sensor. * Wiring (I2C): * Sensor -> Arduino * GND -> GND * ADD -> NC * SDA -> A4 * SCL -> A5 * VCC -> +5V * */ #include "MySensorWrapperBH1750.h" MySensorWrapperBH1750::MySensorWrapperBH1750(uint8_t sensor_id) { _sensor_id = sensor_id; MyMessage _msg(_sensor_id, V_LEVEL); } MySensorWrapperBH1750::~MySensorWrapperBH1750() { } void MySensorWrapperBH1750::Setup() { // TODO: Set initialization mode // Default mode: // Start measurement at 1lx resolution. Measurement time is approx 120ms. // #define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // Start measurement at 1lx resolution. Measurement time is approx 120ms. // Device is automatically set to Power Down after measurement. // #define BH1750_ONE_TIME_HIGH_RES_MODE 0x20 _sensor.begin(); } void MySensorWrapperBH1750::Present() { present(_sensor_id, S_LIGHT_LEVEL); } void MySensorWrapperBH1750::UpdateSensorValue() { // Fetch light in Lux from BH1750 sensor uint16_t newValue = _sensor.readLightLevel();// Get Lux value if (isnan(newValue)) { #ifdef MY_DEBUG Serial.println("Failed reading Light from BH1750"); #endif } else if (newValue != _lastValue) { #ifdef MY_DEBUG Serial.print("Lux: "); Serial.println(newValue); #endif send(_msg.set(newValue)); _lastValue = newValue; } } And for the DHT I've created the following class: MySensorWrapperDHT.h // MySensorWrapperDHT.h #ifndef _MYSENSORWRAPPERDHT_h #define _MYSENSORWRAPPERDHT_h //Need to add to project Version.h and MyEepromAdresses.h #include "MySensorsCore.h" #include "DHT.h" class MySensorWrapperDHT { public: MySensorWrapperDHT(uint8_t sensor_temp_id, uint8_t sensor_humd_id, uint8_t sensor_pin = 3); ~MySensorWrapperDHT(); void Setup(); void Present(); void UpdateSensorValue(); private: uint8_t _sensorTempId; uint8_t _sensorHumdId; uint8_t _sensorPin; DHT _sensor; MyMessage _msgTemp; MyMessage _msgHumd; float _lastTempValue; float _lastHumdValue; }; #endif MySensorWrapperDHT.cpp /** * Name: MySensorWrapperDHT * Created: 20-Aug-16 22:47:51 * Author: Daniel * Version 0.1 - Draft * ******************************* * * MySensors Wrapper for DHT sensor. * Wiring (): * Sensor -> Arduino * GND -> GND * OUT -> D3 * VCC -> +5V * * NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1 * to 3.3V instead of 5V! * Connect pin 2 of the sensor to whatever your DHTPIN is * Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor * https://github.com/adafruit/DHT-sensor-library/blob/master/examples/DHTtester/DHTtester.ino */ #include "MySensorWrapperDHT.h" MySensorWrapperDHT::MySensorWrapperDHT(uint8_t sensor_temp_id, uint8_t sensor_humd_id, uint8_t sensor_pin) { _sensorTempId = sensor_temp_id; _sensorHumdId = sensor_humd_id; _sensorPin = sensor_pin; MyMessage _msgTemp(_sensorTempId, V_TEMP); MyMessage _msgHumd(_sensorHumdId, V_HUM); } MySensorWrapperDHT::~MySensorWrapperDHT() { } void MySensorWrapperDHT::Setup() { _sensor.setup(_sensorPin, DHT::DHT22); } void MySensorWrapperDHT::Present() { present(_sensorTempId, S_TEMP); present(_sensorHumdId, S_HUM); } void MySensorWrapperDHT::UpdateSensorValue() { // TODO: really needed? wait(_sensor.getMinimumSamplingPeriod()); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float currentTempValue = _sensor.getTemperature(); float currentHumdValue = _sensor.getHumidity(); // Check if any reads failed and exit early (to try again). if (isnan(currentTempValue) || isnan(currentHumdValue) ){ Serial.println("Failed to read from DHT sensor!"); } else { // Update temperature from DHT sensor if (currentTempValue != _lastTempValue) { _lastTempValue = currentTempValue; send(_msgTemp.set(currentTempValue, true)); #ifdef MY_DEBUG Serial.print("Temp: "); Serial.println(currentTempValue); #endif } // Update humidity from DHT sensor if (currentHumdValue != _lastHumdValue) { _lastHumdValue = currentHumdValue; send(_msgHumd.set(currentHumdValue, 1)); #ifdef MY_DEBUG Serial.print("Hum: "); Serial.println(currentHumdValue); #endif } } } And to my surprise the footprint after compiling is even smaller, 18,374 bytes (59%) of program storage space and 913 bytes (44%) of dynamic memory with a single .ino versus 17,748 bytes (58%) of program storage space and 857 bytes (42%) of dynamic memory the above project in VisualMicro. Both results with MY_DEBUG defined. Next step is to create classes to manage switches, relays and LEDs. Once again thank you all for the help and fell free to share your opinions about the way I'm trying to do things. Best regards
  • Relay output off on comms timeout?

    3
    0 Votes
    3 Posts
    831 Views
    lassenieL
    @mfalkvidd Thank you for your valuable suggestions - they all look very relevant. Perhaps I am overlooking something in the documentation, but I wonder if any existing controllers out there will get the node's relay outputs in the right state again after a node restart, if it always starts up in off state. Besides that, how can I reliably detect communication in the node, such as I_HEARTBEAT/I_HEARTBEAT_RESPONSE? As far as I know, such internal messages do not arrive through the recieve(...) API function. I will need to see some incoming messages (also from existing controller implementations) - otherwise I would get timeouts. Best regards Lasse
  • Best IDE to use for MySensors projects

    atmel studio eclipse debug visualmicro ide
    48
    0 Votes
    48 Posts
    22k Views
    YveauxY
    @rb3rg I know. It's even bundled with the installer now. My post you're referring to is 12 months old...
  • software AES encryption for NRF24

    43
    5 Votes
    43 Posts
    21k Views
    AnticimexA
    Me neither. I care about security, not obscurity. I see no reason to encrypt a '1' or a '0' and digital streams like audio and video is not supported anyway. But exchange of constant (but random) data is already used and supported since signing is based on nonce exchange. But I believe IV:s "evolve" with the messages encrypted which implies the messages need to be exchanged trustworthy and sender and receiver need to be om sync. But I know to little about that to be sure. In any case, I welcome any development that adds to security, and will happily review such code, but I don't have the bandwidth nor motivation to "drive" the development of encryption in the core library as I don't feel it adds enough value to be worth the effort.
  • V_RGB light strip

    3
    0 Votes
    3 Posts
    1k Views
    CrankyCoderC
    @TheoL I think I may already be using your code :) just can't figure out how to send messages to the node. I am using a mqtt client gateway. So I have my mqtt nodes but looking for the format of the messages to send, and then I can try to get it in to openhab.
  • {DEV} Multi-Sensor Node goes into boot loop

    21
    0 Votes
    21 Posts
    5k Views
    joachimJ
    I found out that adding a sleep(10) between 2 consecutive 'send' does help a lot
  • 0 Votes
    9 Posts
    2k Views
    Tagore.PDET
    I think i get it, @tlpeter : MyMessage msgHumSoil(SOILHUMDITY, V_LEVEL); void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Sensor POT", "1.1"); wait(MESSAGEWAIT); // Register all sensors to gateway (they will be created as child devices) present(SOILHUMDITY, S_MOISTURE);
  • Adding internal messages I_HEARTRATE_REQUEST and I_HEARTRATE_RESPONSE

    5
    0 Votes
    5 Posts
    2k Views
    G
    Hi @tekka. I appreaciate your answer and share your opinion. Lets focus our efforts in other topics.
  • SaveState(): How to save and load bigger value

    3
    0 Votes
    3 Posts
    2k Views
    hekH
    @vga, Just watch out writing too frequently to the poor EEPROM.
  • RS485 communication GW - Node Problem

    4
    0 Votes
    4 Posts
    1k Views
    H
    @hek Sorry for my Late reply. I had an issue with the max485 (ground problem) and the declaration of the node id (was at the wrong position in the sketch). I think, it would be better, if this is also in the examples in the ms library. It cost me some time to find this solution for the node id. But i wasn't sure, if it was the parent or node id
  • Sleeping while waiting for double click (delayed sleep)

    6
    0 Votes
    6 Posts
    3k Views
    D
    Thanks, I will most likely do it like you are suggesting. About reset, you mean setting it to "off" state after click or? The code above sends only one action per press, so it is either as "click", or a "double click" or a "hold released" (you can even send a "hold started" and "I'm holding...I'm holding...I'm holding...I'm holding..." events, but I do not need them for now). All the logic about counting etc is nicely handled by the OneButtonLibrary, it works much much better then the other solutions I found on the net (I even started writing my own logic, but being somewhat "experienced" developer I figured that someone has allready tested it better then me, and I was right :) ) I use domoticz as controller and it has option for the "contact" type of switch, which gets triggererd each time I press the button/send the ON state. It works nice so far, so I wasn't going much into details about hows and whys :)
  • Can someone confirm UDP gateway is working in 2.0.0?

    3
    0 Votes
    3 Posts
    917 Views
    hekH
    @rb3rg Could you create a pull request with the relevant changes?
  • AC IR code decrypting

    42
    0 Votes
    42 Posts
    18k Views
    dpressleD
    Hi All, Library can be found here: GitHub It contains a test ino to test the library and a ino to work with mysensors. If you have any comments and or questions please dont hesitate to ask/comment. Thanks to all of you who helped in this topic and especially to @joker_mkd who donated his gree code document.
  • Port MySensors or my project?

    2
    0 Votes
    2 Posts
    663 Views
    scalzS
    Hello. Most of the RFM69 libs work with esp8266. I use mysensors with rfm69 and esp, or, radiohead and lowpowerlab. work too.

8

Online

11.7k

Users

11.2k

Topics

113.1k

Posts