Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
core_cC

core_c

@core_c
About
Posts
38
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Browser-based firmware generator
    core_cC core_c

    I am one of those few users that opened chrome://flags, and set:
    Enable WebUSB support: disabled.
    I already have installed a tool to program my Arduinos. I guess, it's the first thing most people install after aquiring an Arduino.
    I also do not understand why i would ever use a cloud.
    Perhaps i am "too oldskool".. using a browser to find what i search for, and (if it is code,) then download it.
    When i want code, i do not care how i get it. Important is, that i can download it..
    The bare product is what counts..

    Development

  • Message is send twice
    core_cC core_c

    About your battery level send question, here's some explanation:
    The intention is to let your node sleep when nothing happens.
    Only when the generator pin changes, it interrupts the sleep cycle, and wakes up the node. It then checks the current generator pin state and sends the appropriate message. Then it goes to sleep again.
    However, it does not sleep forever. At regular intervals the battery level is send. So every BATTERY_REPORT_INTERVAL milliseconds the current sleep cycle ends (because the timer has counted down and reached its end), and the battery level is send.
    The program keeps doing this: Sleep, and wake up if the pin changed, and/or wake up when the battery level should be send.

    Troubleshooting

  • Message is send twice
    core_cC core_c

    @esawyja i made the changes for you in my post made earlier^^

    Troubleshooting

  • Message is send twice
    core_cC core_c

    @esawyja attachInterrupt() should only be done once, in the setup() function.

    Troubleshooting

  • Message is send twice
    core_cC core_c

    @esawyja You are right. I made a mistake. This should fix it:
    Change this line:

    uint32_t sleep_time_left = battery_report_time - millis();
    

    into this:

    long sleep_time_left = battery_report_time - millis();
    

    A variable of type long can hold a negative number, but an unsigned long (same as uint32_t) can never hold a negative number (because it is unsigned, no sign, no minus sign, no negative).
    So, if (sleep_time_left < 0) will never be true.. That was the mistake.

    I was also wondering if the generator would produce interrupts without using attachInterrupt().
    Without that, you can still poll the generator pin, and see if the value changed (what is happening now), but the sleep() cycle would not be interrupted when the pin changed.
    To be on the safe side, i would also add the following to your code:

    void setup() {
      attachInterrupt(digitalPinToInterrupt(GENERATOR_PIN), generator_pin_interrupt_handler, CHANGE);
    }
    

    Hopefully that'll make it work as intended.

    Troubleshooting

  • Message is send twice
    core_cC core_c

    @esawyja In your last program, your battery level is only send when the generator changed state.
    Probably you want to let the battery report it's level at regular intervals, independent of the generator state.
    Boots33 pointed out how to know if a message has been sent succesfully.
    Here is a version of your sketch that does both things:

    #define RETRY_TIMES 3
    #define RETRY_WAIT 10000
    #define BATTERY_REPORT_INTERVAL 60000
    
    int oldValue;
    uint32_t battery_report_time;
    
    volatile bool generator_pin_changed = false;
    volatile int generator_pin_value;
    void generator_pin_interrupt_handler() {
      generator_pin_changed = true;
      generator_pin_value = digitalRead(GENERATOR_PIN);
    }
    
    void setup() {
      oldValue = digitalRead(GENERATOR_PIN);
      sendGeneratorMsg(oldValue==HIGH?0:1);
      battery_report_time = millis() + BATTERY_REPORT_INTERVAL;
      attachInterrupt(digitalPinToInterrupt(GENERATOR_PIN), generator_pin_interrupt_handler, CHANGE);
    }
    
    void loop() {
      int value = digitalRead(GENERATOR_PIN);
      if (value != oldValue) {
        oldValue = value;
        if (value == LOW) {
          Serial.println("Generator RUNNING - SENDING");
          sendGeneratorMsg(1);
        } else {
          Serial.println("Generator NOT running - SENDING....");
          sendGeneratorMsg(0);
        }
      }
      long sleep_time_left = battery_report_time - millis();
      if (sleep_time_left < 0) {
        battery_report_time = millis() + BATTERY_REPORT_INTERVAL;
        sleep_time_left = BATTERY_REPORT_INTERVAL;
        read_batt();
      }
      sleep(digitalPinToInterrupt(GENERATOR_PIN), CHANGE, sleep_time_left);    
    }  
    
    void sendGeneratorMsg(int state) {
      for (int i=0; i<RETRY_TIMES; i++) {
        if (send(msgGENERATOR.set(state))) {
          Serial.println("Generator message sent");
          return;
        }
        wait(RETRY_WAIT);
      }
      Serial.println("Failed to send generator message");
    }
    
    void read_batt() {
      wait(15000);
      int sensorValue = analogRead(BATTERY_SENSE_PIN);
      float batteryV = sensorValue * volt_value;
      send(batt_msg.set(batteryV,2));
    }
    

    EDIT: I have changed ^^the code^^ with the suggestions i made in my next post.

    Troubleshooting

  • Synchronising Light switch
    core_cC core_c

    cool.
    nothing too much in code, nor in wiring.
    :+1:

    My Project light switch

  • Browser-based firmware generator
    core_cC core_c

    the word "Generator" scores. :)
    i personally like "MyGenerator" most..

    Development

  • Message is send twice
    core_cC core_c

    @esawyja No, it does not matter if it's active low or active high. I was only thinking that it could be an oversight.. something wrong in code that someone (possibly) keeps missing because they are assuming that that part of the code is correct.

    About what you said previously: "looks like it detects the change, but does not do anything":
    Correct me if i'm wrong, but this looks like it detects, and does something:

    interupt
    1
    5429 MCO:BGN:INIT OK,TSP=1
    1
    Generator NOT running - SENDING....
    5441 TSF:MSG:SEND,11-11-0-0,s=6,c=1,t=2,pt=2,l=2,sg=0,ft=0,st=OK:0
    

    After that, when the generator did not change state anymore, you will see a stream of only sleep/wake-up messages (a stream, because sleeptime is 0). I see that stream start at 5648.

    In your current program, i'm curious if that second send() is really needed (the last send in the "send,wait(10000),send" sequence).
    But anyway, your skills got it working.. :heavy_check_mark:

    Troubleshooting

  • Building a LED status
    core_cC core_c

    I know 0.00001 about Vera (i know just the name), but i probably can help you light up an RGB LED.
    Can you post any code you already have running on an Arduino?
    I know there is a S_RGB_LIGHT message in MySensors.. So i guess: it is also known/recognized by Vera.

    shoot!

    My Project

  • Browser-based firmware generator
    core_cC core_c

    @rakeshpai The idea of creating a generator is really cool. There are many non-programmers out there, just wanting their sensor-network up and running.
    I bet you finish this project, and make many people happy. Keep up the good work rakeshpai.
    The awesome MySensors generator

    Development

  • Message is send twice
    core_cC core_c

    @esawyja I don't really know what your goal is, but is it correct to send a 1 if the generator is running, and to send a 0 when it's not running?
    It seems more logical to send a 1 to enable a device, and 0 to disable it.

    Could it be that you disable the generator, and it simply is not responding anymore?

    Troubleshooting

  • Message is send twice
    core_cC core_c

    From your log i can see that your node goes to sleep, and immediately wakes up again.
    I don't know the value of your SLEEP_TIME, but i guess it's not a value close to 0.
    It looks like your sleep() cycle is interrupted by a change on your GENERATOR_PIN.
    What if you inserted a short pause just before going to sleep, just after send(msgGENERATOR)?

    Another way to handle interrupts:
    Your code uses an interrupt to detect changes of the generator status, but you handle possible changes outside the interrupt-handler (the code that is executed whenever there was a change on the pin). Your sleep function can exit in two ways: by interrupt OR by the SLEEP_TIME expiring. Your code does the same in both cases. Even if there was no change on the pin, but the timer expired, a message will be send.
    If you only want to send a message when there was actually a change of signal on the pin, i would use an interrupt-handler that detects any change, and let the loop() code know about it.

    volatile bool generator_pin_changed = false;
    volatile int generator_pin_value;
    void generator_pin_interrupt_handler() {
      generator_pin_changed = true;
      generator_pin_value = digitalRead(GENERATOR_PIN);
    }
    
    void setup() {
      attachInterrupt(digitalPinToInterrupt(GENERATOR_PIN), generator_pin_interrupt_handler, CHANGE);
    }
    
    void loop() {
      if (generator_pin_changed) {
        generator_pin_changed = false;  /* reset for next detection */
        if (generator_pin_value == LOW) {
          Serial.println("Generator RUNNING");
          send(msgGENERATOR.set(1));
        } else {
          Serial.println("Generator NOT running - SENDING....");
          send(msgGENERATOR.set(0));
        }
      }
      wait(200);
      /* sleep again if the timer expired. stop sleeping if woken up by an interrupt. */
      while (sleep(digitalPinToInterrupt(GENERATOR_PIN), CHANGE, SLEEP_TIME) < 0);
    }
    
    Troubleshooting

  • Running MySensors on ATTiny85
    core_cC core_c

    check!
    funny.. Your post's image, and ebay's image, are both swapped horizontally.
    Or is it the chinese printing it wrongly?

    EDIT: But they have the price just right ;)

    EDIT 2: Interesting topic tekka.
    @Tinimini: What did you find out using an ATtiny85? any tests? any results?.. any problems?

    Hardware

  • Running MySensors on ATTiny85
    core_cC core_c

    of course!..
    I know there is an (at least 1) AVR that doesn't even have RAM. So any code it runs, would have to be very optimized (registers is all one can use). That is no MCU one would use for a typical MySensors node.. true. But there are ATtiny's that can do a lot more.
    I am interested in exploiting a device to the max. If it has 2 timers, and you never use one of them,.. that's a shame. It is one of the greatest features of an MCU: timers.
    Everyone their own hobby ;)

    Just look at this tiny thing:
    http://www.microchip.com/wwwproducts/en/ATTINY85
    It's a marvel..

    Hardware

  • Running MySensors on ATTiny85
    core_cC core_c

    i like it small..
    "The smallest tinyAVR MCU measures only 1.5 mm x 1.4 mm." (Atmel website).
    That is probably no good choice to use for a MySensors node (RAM?), but (for example) i could make any sensor an I2C sensor.
    Or, if i need to detect interrupts for some hardware/sensor, i could use an ATtiny for that purpose (solely).
    I guess i'll need to improve my soldering skills with the smallest one. :)

    Hardware

  • Running MySensors on ATTiny85
    core_cC core_c

    I myself was searching for ATtiny articles (Arduino & MySensors). I found not much (far less as i had expected).
    I'm very interested in a ATtiny (and therefore i replied to this topic, so i'll get notifications :)

    Hardware

  • receive() a message while in low power mode?
    core_cC core_c

    I haven't tried it out for myself yet, so i can not give you my experiences but there is a controller that can do what you want.
    This is what the myHouse controller says:

    https://sourceforge.net/p/my-house/wiki/faq/#how-is-the-mysensors-smart-sleep-handled-in-myhouse

    General Discussion

  • MySensors booth at Eindhoven Maker Faire!
    core_cC core_c

    That will be fun. Count me in! I'm looking forward to meet you geeks in person.
    Let the nodes connect..

    Announcements

  • 💬 myHouse
    core_cC core_c

    For me myHouse is by far the best controller i tried. I can configure it the way i want.. modules, widgets, nice graphs, webcams.. you name it! There are just so many options.
    I did not yet try out all the things i like (like Slack bot, or running scripts, combining multiple sensors in one graph,.. etc.), but so far: i'm impressed.
    My MySensors sensors (i'm not stuttering) are now being displayed in myHouse.
    The only thing worth mentioning is: One should take time to read the documentation well before start changing the config file. It's not so hard to comprehend but i guess for some it can get complicated handling so many nested structures. A good editor, to change the config, can make things a lot easier (one that can collapse/expand, or even correct syntax).
    I followed the instructions, created my own design/layout, got myself some API-keys, installed the software, and all worked the first time. And i had to learn about Linux as i went along :) because i'm a newbee Linux user. --help
    Great job user2684..

    Announcements
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular