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
  1. Home
  2. Development
  3. can't reboot a node with a certain sketch loaded

can't reboot a node with a certain sketch loaded

Scheduled Pinned Locked Moved Development
5 Posts 4 Posters 1.8k 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.
  • joshwJ Offline
    joshwJ Offline
    joshw
    wrote on last edited by joshw
    #1

    I made an attempt at combining the DallasTemperatureSensor and RelayActuator sketches, and after a couple tries I thought I had gotten it right - everything works as intended, except for one thing. If I try to reboot the node from MYSController (either individually or as a broadcast to all nodes), it shuts down (relays click off) but never starts back up. Node has no problem rebooting with a different sketch loaded. Also, it starts working fine again after a power cycle or manual reset.

    What did I miss? It's driving me nuts.

    Thanks in advance,
    Josh

    #include <MySensor.h>
    #include <SPI.h>
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    #define ONE_WIRE_BUS 3 // Pin where dallas sensor is connected 
    #define MAX_ATTACHED_DS18B20 16
    #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    unsigned long SLEEP_TIME = 10000; // Sleep time between reads (in milliseconds)
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    MySensor gw;
    
    // int node_id = 99;
    
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors = 0;
    boolean receivedConfig = false;
    boolean metric = false;
    // Initialize temperature message
    MyMessage msg(5, V_TEMP);
    
    void setup()
    {
    
      // Startup OneWire
      sensors.begin();
    
      // Initialize library and add callback for incoming messages
      // gw.begin(incomingMessage, node_id, true);
      gw.begin(incomingMessage, AUTO, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relay plus Temp", "1.6");
    
      // Fetch relay status
      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)
        gw.present(sensor, S_LIGHT);
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, gw.loadState(sensor) ? RELAY_ON : RELAY_OFF);
      }
      // Fetch the number of attached temperature sensors
      numSensors = sensors.getDeviceCount();
    
      // Present all sensors to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
        gw.present(i, S_TEMP);
      }
    }
    
    
    void loop()
    {
      // Alway process incoming messages whenever possible
      gw.process();
    
      // Fetch temperatures from Dallas sensors
      sensors.requestTemperatures();
    
      // Read temperatures and send them to controller
      for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
    
        // Fetch and round temperature to one decimal
        float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
    
        // Only send data if temperature has changed and no error
        if (lastTemperature[i] != temperature && temperature != -127.00) {
    
          // Send in the new temperature
          gw.send(msg.setSensor(i).set(temperature, 1));
          lastTemperature[i] = temperature;
        }
      }
      gw.wait(SLEEP_TIME);
    }
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type == V_LIGHT) {
        // Change relay state
        digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF);
        // Store state in eeprom
        gw.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());
      }
    }
    
    hekH 1 Reply Last reply
    0
    • G Offline
      G Offline
      gonzalonal
      wrote on last edited by
      #2

      Hi, I have a similar issue.
      Myabe you can post your peoblem in the following thread:
      http://forum.mysensors.org/topic/838/windows-gui-controller-for-mysensors/209

      regards.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zeph
        Hero Member
        wrote on last edited by
        #3

        How much RAM do you have left?

        I don't know if it's related, but it's one of the first things I check (nowadays, having too little remaining hair to spare) when things go weird and I have no other good hypothesis. If there's plenty of RAM left, I keep looking for another cause. (I don't currently have any theory about what really happens when you try to reboot - if it successfully gets all the way to a uC reset and hardware reboot, then memory would be reallocated from scratch so this would not apply, so an out of memory bug would probably have to happen earlier in the process).

        What matters here is the space between the stack and the heap (without tracing any freed blocks on the heap to get total free memory). I use a variant of this technique which uses very little program and data memory:

        http://forum.pololu.com/viewtopic.php?f=10&t=989&view=unread#p4218

        1 Reply Last reply
        0
        • joshwJ joshw

          I made an attempt at combining the DallasTemperatureSensor and RelayActuator sketches, and after a couple tries I thought I had gotten it right - everything works as intended, except for one thing. If I try to reboot the node from MYSController (either individually or as a broadcast to all nodes), it shuts down (relays click off) but never starts back up. Node has no problem rebooting with a different sketch loaded. Also, it starts working fine again after a power cycle or manual reset.

          What did I miss? It's driving me nuts.

          Thanks in advance,
          Josh

          #include <MySensor.h>
          #include <SPI.h>
          #include <DallasTemperature.h>
          #include <OneWire.h>
          
          #define ONE_WIRE_BUS 3 // Pin where dallas sensor is connected 
          #define MAX_ATTACHED_DS18B20 16
          #define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
          #define NUMBER_OF_RELAYS 2 // Total number of attached relays
          #define RELAY_ON 0  // GPIO value to write to turn on attached relay
          #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
          
          unsigned long SLEEP_TIME = 10000; // Sleep time between reads (in milliseconds)
          OneWire oneWire(ONE_WIRE_BUS);
          DallasTemperature sensors(&oneWire);
          MySensor gw;
          
          // int node_id = 99;
          
          float lastTemperature[MAX_ATTACHED_DS18B20];
          int numSensors = 0;
          boolean receivedConfig = false;
          boolean metric = false;
          // Initialize temperature message
          MyMessage msg(5, V_TEMP);
          
          void setup()
          {
          
            // Startup OneWire
            sensors.begin();
          
            // Initialize library and add callback for incoming messages
            // gw.begin(incomingMessage, node_id, true);
            gw.begin(incomingMessage, AUTO, true);
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("Relay plus Temp", "1.6");
          
            // Fetch relay status
            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)
              gw.present(sensor, S_LIGHT);
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);
              // Set relay to last known state (using eeprom storage)
              digitalWrite(pin, gw.loadState(sensor) ? RELAY_ON : RELAY_OFF);
            }
            // Fetch the number of attached temperature sensors
            numSensors = sensors.getDeviceCount();
          
            // Present all sensors to controller
            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
              gw.present(i, S_TEMP);
            }
          }
          
          
          void loop()
          {
            // Alway process incoming messages whenever possible
            gw.process();
          
            // Fetch temperatures from Dallas sensors
            sensors.requestTemperatures();
          
            // Read temperatures and send them to controller
            for (int i = 0; i < numSensors && i < MAX_ATTACHED_DS18B20; i++) {
          
              // Fetch and round temperature to one decimal
              float temperature = static_cast<float>(static_cast<int>((sensors.getTempFByIndex(i)) * 10.)) / 10.;
          
              // Only send data if temperature has changed and no error
              if (lastTemperature[i] != temperature && temperature != -127.00) {
          
                // Send in the new temperature
                gw.send(msg.setSensor(i).set(temperature, 1));
                lastTemperature[i] = temperature;
              }
            }
            gw.wait(SLEEP_TIME);
          }
          
          void incomingMessage(const MyMessage &message) {
            // We only expect one type of message from controller. But we better check anyway.
            if (message.type == V_LIGHT) {
              // Change relay state
              digitalWrite(message.sensor - 1 + RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF);
              // Store state in eeprom
              gw.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());
            }
          }
          
          hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #4

          @joshw

          Could also be a classic powering issue when using power hungry relays.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zeph
            Hero Member
            wrote on last edited by
            #5

            Could be power I suppose. You say that it reboots OK with other sketches. Do both the relay and temp sensor single-sensor sketches reboot OK?

            I was assuming so, which is why I was thinking something software rather than hardware, but assuming is what gets us stuck, debug wise.

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


            19

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 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
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular