can't reboot a node with a certain sketch loaded
-
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()); } }
-
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/209regards.
-
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
-
Could also be a classic powering issue when using power hungry relays.
-
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.