Skip to content
  • 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
  1. Home
  2. Troubleshooting
  3. Node with Interrupt, sleep and batteries
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Node with Interrupt, sleep and batteries

Scheduled Pinned Locked Moved Troubleshooting
interruptsleep
16 Posts 5 Posters 10.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • martinhjelmareM Offline
    martinhjelmareM Offline
    martinhjelmare
    Plugin Developer
    wrote on last edited by martinhjelmare
    #7

    If you don't need exact time passed, I think you can use a variant of the sensebender sketch sleep and count implementation, but you only increment the counter if woken after timer and not the interrupt. This will not take into account the time that the arduino is awake, so there will be an error. But if you don't do any have lifting or waiting in the loop, it will probably go to sleep quickly. You want to wait for the pulse count from the gateway if you don't have that, but that should only be needed after first boot, correct?

    If you need exact time passed, I can only see two options:

    Either you turn off the interrupt, and only sleep with timer, and add the sleep time to time awake, measured with millis(). This should give you very accurate time passed.

    The other option is asking the gateway/controller for time. Then subtract last time from current time and you will have time passed.

    1 Reply Last reply
    0
    • sundberg84S Offline
      sundberg84S Offline
      sundberg84
      Hardware Contributor
      wrote on last edited by sundberg84
      #8

      @martinhjelmare Time is not an issue.
      I dont want the node to wake up due to the interrupt.

      I want the node to sleep for 15 minutes (aprox), and count the interrups.
      Every 15 min it wakes up and sends the counter.

      What happens is that it wakes up and run the loop (sends counter) after 1-2 minute probably due to an interrupt waking it up. This will not save enough battery.

      Controller: Proxmox VM - Home Assistant
      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

      1 Reply Last reply
      0
      • martinhjelmareM Offline
        martinhjelmareM Offline
        martinhjelmare
        Plugin Developer
        wrote on last edited by martinhjelmare
        #9

        Ok, but you said there is an issue with sending it to sleep for 15 minutes every 2-3 minutes. From that I gather you need to know time better, since you can't avoid waking the node if you have an interrupt attached.

        Would sleeping for 1 minute from timer and counting every wake-up by timer be ok battery-wise? 13 counts will then be ~ 15.6 (+/-) 2.6 minutes, since max time error given by wake-up by interrupt is < 1 minute and you said the interrupts occur on average every 2.5 minutes. 13 / 2.5 = 5.2 minutes. So 13 counts is between 13 and 18.2 minutes. You add a condition that only sends the information after 13 counts. Wake-up by interrupt should only add pulse, check count and go back to sleep for 1 minute if count is not 13. Wake-up by timer checks count and adds +1 to count.

        How would this compare battery-wise to sleeping on average the 2.5 minutes between interrupts and each wake-up use the radio to ask for time from the controller?

        1 Reply Last reply
        0
        • martinhjelmareM Offline
          martinhjelmareM Offline
          martinhjelmare
          Plugin Developer
          wrote on last edited by
          #10

          Maybe you can avoid waking the node if not using the mysensors sleep function? Out of my knowledge scope, though. Have you read this?

          http://gammon.com.au/interrupts

          1 Reply Last reply
          0
          • sundberg84S Offline
            sundberg84S Offline
            sundberg84
            Hardware Contributor
            wrote on last edited by
            #11

            The problem is not sending it to sleep. I use sleep(int interrupt, int mode, unsigned long ms=0) where ms = 900000ms. The intetrupt counts aprox 100-150 interrups before something triggers it back/wakes it (2-3min). I dont know why it wakes here... this happens around 2-3minutes (Its a led/pulse counter for electric).
            Can it run out of memory -128 bytes or something? Its around there (100-150 interrups) it wakes up.

            The only thing i want the node to wake from is that 15 minutes timer and not the interrupt.

            Sleeping 1 min and add counter sounds good, i will try that.
            @martinhjelmare

            Controller: Proxmox VM - Home Assistant
            MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
            MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
            RFLink GW - Arduino Mega + RFLink Shield, 433mhz

            AWIA 1 Reply Last reply
            0
            • sundberg84S sundberg84

              The problem is not sending it to sleep. I use sleep(int interrupt, int mode, unsigned long ms=0) where ms = 900000ms. The intetrupt counts aprox 100-150 interrups before something triggers it back/wakes it (2-3min). I dont know why it wakes here... this happens around 2-3minutes (Its a led/pulse counter for electric).
              Can it run out of memory -128 bytes or something? Its around there (100-150 interrups) it wakes up.

              The only thing i want the node to wake from is that 15 minutes timer and not the interrupt.

              Sleeping 1 min and add counter sounds good, i will try that.
              @martinhjelmare

              AWIA Offline
              AWIA Offline
              AWI
              Hero Member
              wrote on last edited by
              #12

              @sundberg84 Are u sure you are setting the time to 900000ms, using 900000UL? It took me a long time to find out that large (long/ unsigned long) need explicit type specification

              1 Reply Last reply
              0
              • sundberg84S Offline
                sundberg84S Offline
                sundberg84
                Hardware Contributor
                wrote on last edited by sundberg84
                #13

                @AWI Thanks - this is pretty much a copy from my other sketches and it works there.
                But no harm changing it - i will do that.

                You see my code above - but im pretty sure the interrups wakes the node up.

                Controller: Proxmox VM - Home Assistant
                MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                1 Reply Last reply
                0
                • martinhjelmareM Offline
                  martinhjelmareM Offline
                  martinhjelmare
                  Plugin Developer
                  wrote on last edited by
                  #14

                  I think the problem might be that you try to combine the attachInterrupt function that should call an ISR and the mysensors sleep function. The mysensors sleep function handles alot of the required interrupt function logic for you. If you use the attachInterrupt function you have to do that yourself. I might be wrong though, I haven't tried this myself. Maybe @hek can comment?

                  For example the following link says that you have to detach the interrupt inside the ISR to not have it trigger again.
                  http://playground.arduino.cc/Learning/ArduinoSleepCode

                  According to this page, all external interrupt types wake the processor. That's also one of the main points with an interrupt; to be able to wake the processor from sleep.
                  http://gammon.com.au/interrupts

                  1 Reply Last reply
                  2
                  • martinhjelmareM Offline
                    martinhjelmareM Offline
                    martinhjelmare
                    Plugin Developer
                    wrote on last edited by
                    #15

                    I suggest using the mysensors sleep function and checking the return value, as @Yveaux suggested, to determine if onPulse() should be called (after interrupt wake-up), or if it's a timer wake-up.

                    1 Reply Last reply
                    0
                    • sundberg84S Offline
                      sundberg84S Offline
                      sundberg84
                      Hardware Contributor
                      wrote on last edited by
                      #16

                      Yea, now I understand how to use that!! I will do that, thats probably the best... will try!

                      Thanks alot everybody involved! @martinhjelmare @AWI @Yveaux

                      Controller: Proxmox VM - Home Assistant
                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      14

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

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