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!
  • Relay Actuator - send periodic status as heart beat.

    3
    0 Votes
    3 Posts
    3k Views
    D
    Hi, yout post is quit old but I changed your code a bit. Now it sends the status of both relays: long double last_heartbeat_time = millis(); long double HEARTBEAT_TIME = 30000; int oldValue = 0; bool state; MyMessage msg1a(1, V_STATUS); MyMessage msg1b; MyMessage msg2a(2, V_STATUS); MyMessage msg2b; void before() { for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF); } } void setup() { } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay", "1.0"); for (int sensor = 1, pin = RELAY_1; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); } } void loop() { long double temp = (millis() - last_heartbeat_time); if (temp > HEARTBEAT_TIME) { // If it exceeds the heartbeat time then send a heartbeat sendHeartbeat(); send(msg1a.set(msg1b.getBool() ? 1 : 0)); send(msg2a.set(msg2b.getBool() ? 1 : 0)); last_heartbeat_time = millis(); Serial.println("Sent heartbeat" ); } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_STATUS) { // Change relay state digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); if (message.sensor == 1) { msg1b = message; } if (message.sensor == 2) { msg2b = message; } } } rg Denis
  • wait microseconds available?

    3
    0 Votes
    3 Posts
    591 Views
    skywatchS
    @Nca78 That makes perfect sense! - Thanks for the clarification.....Onwards and upwards! ;)
  • [SOLVED] MySensors and DHT22 - difficoulties in getting started

    8
    0 Votes
    8 Posts
    4k Views
    mfalkviddM
    @neo-mod said in [SOLVED] MySensors and DHT22 - difficoulties in getting started: I'm using a NRF24L01+PA+LNA and with BME280 I had an overlapping pin ( I followed the "How to connect the radio" official page). I'll open a new thread asking for advice, quite clearly I'm missing something. I checked my code, and I'm using the BME280 in i2c mode. The i2c pins on Pro Mini are different from the SPI pins so there is no overlap. On esp8266, D1 and D2 are used for i2c which means the CE pin must be moved using MY_RF24_CE_PIN but if you do that it should work.
  • Design question about using interrupts or not

    3
    0 Votes
    3 Posts
    632 Views
    G
    Thanks @mfalkvidd for your quick reply. Indeed it isn't battery powered. I already have a millis() delay loop so checking the swithes is easy then. Thanks again!
  • Serial Gateway w/ MQTT using nodeJS

    6
    3 Votes
    6 Posts
    4k Views
    @electrik There are already plenty of instructions on how you install Node.js and it would be beyond the scope of this topic to do so here. There are so many variables such as operating systems and so on to take into account. After installing Node.js you need to install the Node serialport and Node mqtt. pm2 is a very nice process manager for Node.js that you can use to make sure that your node scripts always is running. It's highly recommended and will make your life easier. In my own installation, I created a sub directory ~/node_modules/serialgwmqtt/ where I saved the app.js script file. Then cd ~/node_modules/serialgwmqtt/ followed by node app.js to make sure that everything works fine. When it does (works fine) you should make it autostart. I added my script to pm2 with the following command: pm2 start app.js --name "serialgwmqtt" (while still in the same directory). check hat it's working by issuing pm2 list I might have been running npm installor something similar also. I'm actually not so clever with these things and I'm sure my instructions can be simplified. The script should also be uploaded so some place to make it available for installing with a simple command. Maybe someone else more node.js-talented person want's to help here. I hope I have't forgotten anything, it's quite straight forward. Things are running rock solid here.
  • is there a #define symbol for the first really free EEPROM address ?

    3
    0 Votes
    3 Posts
    939 Views
    alowhumA
    @mfalkvidd said in is there a #define symbol for the first really free EEPROM address ?: https://github.com/mysensors/MySensors/issues/379 I would like to store some strings in eeprom. The nodes will also use the awesome simple security feature (signing, encryption). I suspect those also write some things to eeprom (I did research this just now, but I wasn't able to find anything on it). Combining all that: would it be smart to just start the storage of these string 'further down', like at 256? As far as I can tell all arduino's have at least 512bytes of eeprom, so then MySensors can still expand into the first 256 in the future, but my code will still be fine?
  • 0 Votes
    5 Posts
    3k Views
    N
    Thank you so much! You just saved me (a certified n00b, I know xD) from countless hours of headache! @mfalkvidd said in ESP8266 MQTT Gateway: Can't Subscribe from Domoticz with Mosquitto running on Pi 3: Just a guess: maybe all you need is to use the rpi3 ip instead of the esp8266 ip?
  • Multiple messages to same node, seems to miss one.

    17
    1
    0 Votes
    17 Posts
    3k Views
    electrikE
    @yveaux Did you find some time already to have a look at this? :-)
  • sha204 library questions

    6
    0 Votes
    6 Posts
    1k Views
    dbagioni77D
    I really dont want to do anything special per se....im just trying to find out if the newer library includes the "return_codes.h" as part of it, do i need a seperate #include statement?
  • signing future

    3
    0 Votes
    3 Posts
    758 Views
    rozpruwaczR
    thank, I will read that :)
  • Multiple sensors

    16
    0 Votes
    16 Posts
    3k Views
    B
    @bogus-exception What do you mean by a HE? Human Engineering? Heavy equipment? High End (system)? Happy Ending :joy: ? BR, Boozz
  • Changing a node not captured by gateway

    8
    0 Votes
    8 Posts
    2k Views
    hakha4H
    You're absolutely right. Should be MyMessage msgC(SSR_C_ID, V_STATUS); Sometimes you get blind when looking for typos. Thank's
  • How to reduce program size

    8
    0 Votes
    8 Posts
    2k Views
    rozpruwaczR
    wow, didn't expect such a response :) thanks. every think is working as expected. I was mislead by some functions from the APDS9930 library that I was not using, but the library was using them in its init function. I solved my problem by reducing size of my code and additionally I removed some functions from the APDS9930 library. So, bottom line. The Arduino IDE uses -fprogram-sections and -Wl,--gc-sections switches during compilation. Those switches remove the unused parts of the compiled objects from the resulting binary.
  • DimmableLED+Relay problem

    4
    0 Votes
    4 Posts
    890 Views
    mfalkviddM
    @mysz0n it is actually the combination that causes the problem. In the library examples, the message is never looked at after send() is called, so overwriting the message is not a problem. But still, it would be nice if someone could spend the time and effort required to change the examples to make them safe to combine.
  • MultiRelayExpanderWithToggleSwitch unstable

    3
    0 Votes
    3 Posts
    1k Views
    A
    Hello I wanted to understand are you using 2 PCF8574? one for input and another for output? also in the code which entries are to add the relays and assign a specific button? the code if inserted on wemos d1 works? sorry for the many questions because I have to put 8 relays controlled with 8 buttons and interface with domoticz thank you
  • This topic is deleted!

    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • esp8266 updating firmware on another esp8266

    3
    1 Votes
    3 Posts
    773 Views
    gohanG
    You could also consider the approach of iotappstory.con
  • Genuino/Arduino 101

    3
    0 Votes
    3 Posts
    1k Views
    marceltrapmanM
    I now have an Udoo x86 as well and I like it. Before I start testing myself, did you manage to get the MySensors Gateway to work?
  • Version 2.3.0 with RFM69HW - Problem communication

    2
    0 Votes
    2 Posts
    634 Views
    pepsonP
    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(); } } }
  • Many compilation errors with mySensor 2.2

    5
    0 Votes
    5 Posts
    2k Views
    djdehaanD
    Well, problem solved. I removed the ESP8266 harware libs and reinstalled them now using the Boards Manager. Then it works fine. But a manual download of the ESP8266 hardware lib causes all these comilation errors. Thanks.

8

Online

11.7k

Users

11.2k

Topics

113.0k

Posts