Shield going inactive


(Malcolm Talley) #1

So here is my development scenario. Tell me if I’m doing something wrong:

  1. I developed a device type named “RV Switcher”. There is code there to accomplish what I want to do.
  2. I’ve developed accompanying code for my Arduino and loaded it on. I used the On/Off with network activity monitor example as a basis.
  3. I have my Arduino with shield running, go into the IOS app and Add Device. I press the switch button on the shield. It usually adds within a short time.
  4. I go into my “Devices” list on the web, find the device and rename it and assign it a type of “RV Switcher”.
  5. I try to start testing everything, but within a few minutes I find that my Arduino is “INACTIVE” on the devices page. I end up having to go through steps 3 and 4 again. Shield goes inactive after about 5.5 minutes.

Ideas?

Also, separate issue (potentially) is that messages are not being received by the shield from pressing buttons on my phone’s interface (though the event log says the correct messages are being sent to the device).


(Andrew Urman) #2

What sketch is on the Arduino? It’s not going to sleep at all is it?


(Malcolm Talley) #3

Here’s the sketch I’m using:

//*****************************************************************************
/// @file
/// @brief
///   RV Switches 
/// @note
///
//*****************************************************************************
#include <SoftwareSerial.h> 
#include <SmartThings.h>

//*****************************************************************************
// Pin Definitions    | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                    V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
#define PIN_SWITCH1     22
#define PIN_SWITCH2     24
#define PIN_SWITCH3     26
#define PIN_SWITCH4     28
#define PIN_SWITCH5     30
#define PIN_SWITCH6     32
#define PIN_SWITCH7     34
#define PIN_SWITCH8     36

#define PIN_THING_RX    3
#define PIN_THING_TX    2

//*****************************************************************************
// Global Variables   | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                    V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
SmartThingsCallout_t messageCallout;    // call out function forward decalaration
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout);  // constructor

bool isDebugEnabled;    // enable or disable debug in this example
int stateSwitch1;           // state to track last set value of switch 1
int stateSwitch2;           // state to track last set value of switch 2
int stateSwitch3;           // state to track last set value of switch 3
int stateSwitch4;           // state to track last set value of switch 4
int stateSwitch5;           // state to track last set value of switch 5
int stateSwitch6;           // state to track last set value of switch 6
int stateSwitch7;           // state to track last set value of switch 7
int stateSwitch8;           // state to track last set value of switch 8
int stateNetwork;

//*****************************************************************************
// Local Functions  | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                  V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void on1()
{
  stateSwitch1 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH1, HIGH);  // turn relay on
  smartthing.send("on1");           // send message to cloud
}

void off1()
{
  stateSwitch1 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH1, LOW);   // turn relay off
  smartthing.send("off1");          // send message to cloud
}

void on2()
{
  stateSwitch2 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH2, HIGH);  // turn relay on
  smartthing.send("on2");           // send message to cloud
}

void off2()
{
  stateSwitch2 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH2, LOW);   // turn relay off
  smartthing.send("off2");          // send message to cloud
}

void on3()
{
  stateSwitch3 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH3, HIGH);  // turn relay on
  smartthing.send("on3");           // send message to cloud
}

void off3()
{
  stateSwitch3 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH3, LOW);   // turn relay off
  smartthing.send("off3");          // send message to cloud
}

void on4()
{
  stateSwitch4 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH4, HIGH);  // turn relay on
  smartthing.send("on4");           // send message to cloud
}

void off4()
{
  stateSwitch4 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH4, LOW);   // turn relay off
  smartthing.send("off4");          // send message to cloud
}

void on5()
{
  stateSwitch5 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH5, HIGH);  // turn relay on
  smartthing.send("on5");           // send message to cloud
}

void off5()
{
  stateSwitch5 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH5, LOW);   // turn relay off
  smartthing.send("off5");          // send message to cloud
}

void on6()
{
  stateSwitch6 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH6, HIGH);  // turn relay on
  smartthing.send("on6");           // send message to cloud
}

void off6()
{
  stateSwitch6 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH6, LOW);   // turn relay off
  smartthing.send("off6");          // send message to cloud
}

void on7()
{
  stateSwitch7 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH7, HIGH);  // turn relay on
  smartthing.send("on7");           // send message to cloud
}

void off7()
{
  stateSwitch7 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH7, LOW);   // turn relay off
  smartthing.send("off7");          // send message to cloud
}

void on8()
{
  stateSwitch8 = 1;                 // save state as 1 (on)
  digitalWrite(PIN_SWITCH8, HIGH);  // turn relay on
  smartthing.send("on8");           // send message to cloud
}

void off8()
{
  stateSwitch8 = 0;                 // set state to 0 (off)
  digitalWrite(PIN_SWITCH8, LOW);   // turn relay off
  smartthing.send("off8");          // send message to cloud
}

//*****************************************************************************
void setNetworkStateLED()
{
  SmartThingsNetworkState_t tempState = smartthing.shieldGetLastNetworkState();
  if (tempState != stateNetwork)
  {
    switch (tempState)
    {
      case STATE_NO_NETWORK:
        if (isDebugEnabled) Serial.println("NO_NETWORK");
        smartthing.shieldSetLED(2, 0, 0); // red
        break;
      case STATE_JOINING:
        if (isDebugEnabled) Serial.println("JOINING");
        smartthing.shieldSetLED(2, 0, 0); // red
        break;
      case STATE_JOINED:
        if (isDebugEnabled) Serial.println("JOINED");
        smartthing.shieldSetLED(0, 0, 0); // off
        break;
      case STATE_JOINED_NOPARENT:
        if (isDebugEnabled) Serial.println("JOINED_NOPARENT");
        smartthing.shieldSetLED(2, 0, 2); // purple
        break;
      case STATE_LEAVING:
        if (isDebugEnabled) Serial.println("LEAVING");
        smartthing.shieldSetLED(2, 0, 0); // red
        break;
      default:
      case STATE_UNKNOWN:
        if (isDebugEnabled) Serial.println("UNKNOWN");
        smartthing.shieldSetLED(0, 2, 0); // green
        break;
    }
    stateNetwork = tempState; 
  }
}

//*****************************************************************************
// API Functions    | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
//                  V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
//*****************************************************************************
void setup()
{
  // setup default state of global variables
  isDebugEnabled = true;
  stateSwitch1 = 0;                 // matches state of hardware pin set below
  stateSwitch2 = 0;                 // matches state of hardware pin set below
  stateSwitch3 = 0;                 // matches state of hardware pin set below
  stateSwitch4 = 0;                 // matches state of hardware pin set below
  stateSwitch5 = 0;                 // matches state of hardware pin set below
  stateSwitch6 = 0;                 // matches state of hardware pin set below
  stateSwitch7 = 0;                 // matches state of hardware pin set below
  stateSwitch8 = 0;                 // matches state of hardware pin set below
  
  // setup hardware pins 
  pinMode(PIN_SWITCH1, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH1, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH2, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH2, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH3, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH3, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH4, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH4, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH5, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH5, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH6, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH6, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH7, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH7, LOW);   // set value to LOW (off) to match state=0
  pinMode(PIN_SWITCH8, OUTPUT);     // define pin as an output
  digitalWrite(PIN_SWITCH8, LOW);   // set value to LOW (off) to match state=0

  stateNetwork = STATE_JOINED;  // set to joined to keep state off if off

  if (isDebugEnabled)
  { // setup debug serial port
    Serial.begin(9600);         // setup serial with a baud rate of 9600
    Serial.println("setup..");  // print out 'setup..' on start
  }
}

//*****************************************************************************
void loop()
{
  // run smartthing logic

  smartthing.run();
  setNetworkStateLED();

}

//*****************************************************************************
void messageCallout(String message)
{
  // if debug is enabled print out the received message
  if (isDebugEnabled)
  {
    Serial.print("Received message: '");
    Serial.print(message);
    Serial.println("' ");
  }

  // if message contents equals to 'on' then call on() function
  // else if message contents equals to 'off' then call off() function
  if (message.equals("On1"))
  {
    on1();
  }
  if (message.equals("Off1"))
  {
    off1();
  }
  if (message.equals("On2"))
  {
    on2();
  }
  if (message.equals("Off2"))
  {
    off2();
  }
  if (message.equals("On3"))
  {
    on3();
  }
  if (message.equals("Off3"))
  {
    off3();
  }
  if (message.equals("On4"))
  {
    on4();
  }
  if (message.equals("Off4"))
  {
    off4();
  }
  if (message.equals("On5"))
  {
    on5();
  }
  if (message.equals("Off5"))
  {
    off5();
  }
  if (message.equals("On6"))
  {
    on6();
  }
  if (message.equals("Off6"))
  {
    off6();
  }
  if (message.equals("On7"))
  {
    on7();
  }
  if (message.equals("Off7"))
  {
    off7();
  }
  if (message.equals("On8"))
  {
    on8();
  }
  if (message.equals("Off8"))
  {
    off8();
  }
  
}

(Todd Wackford) #4

Just a hunch, but try commenting out the setting network state led line in your loop and test it.


(Malcolm Talley) #5

Actually, that was a recent addition. It was going inactive before adding that code, which is why I copy/pasted it to see if I could find a reason why it was dropping. Since adding that code, I haven’t been able to get it online/active, though that was probably more due to frustration and shutting everything down for the evening.


(Andrew Urman) #6

@malcolmtalley have you tried any of the example apps to see if it happens with those too?


(Malcolm Talley) #7

Sorry for the long delay. I will test an example app. That is, once I get my hub to actually add devices again. It has decided to be a pain (again).


(Malcolm Talley) #8

OK, hub issues resolved. Devices connecting and operating.

Put the On/Off Shield code on the Arduino (from the ST website) and started it up. Got the hub to find and add it. Found it on the list of devices on the web. Changed device type to “On/Off Shield (Example)”. Pushed the On/Off button on the ST app on my phone (that’s another subject - shield wasn’t showing that it was receiving data via the debug output). Almost exactly 5.5 minutes after the last operation, the device goes inactive.

Ideas?

Arduino board is a Mega 2560.


(Andrew Urman) #9

when you see it marked as inactive, does it still work?


(Malcolm Talley) #10

OK, so here’s where I am.

I took my earlier program, above, and changed the void loop() to the following:

smartthing.run();
setNetworkStateLED();
delay(1000);

Within setNetworkStateLED, I just cycle through the eight possible states of the shield’s LED (off, 7 colors). I can watch the LED cycle through the colors for hours. That proves the program is running continuously on the Arduino.

I went back and added the call smartthing.shieldGetLastNetworkState(); and log the result each second to the serial port. Even after connecting the shield to the hub (as shown by the app on my phone), the state remains = STATE_UNKNOWN.

Could it be I’m missing some type of constructor or other call that talks to the hub from my program?

Also, as I type this, I’m having problems getting my hub to recognize the shield (again).


(Francisco Tirado) #11

Any progress here? My shield is also going inactive.


(Malcolm Talley) #12

No progress here. I don’t think it is the “INACTIVE” part as much as I never get data coming into the shield.


#13

Did any body figure out why the on off bello program is going only to unknown state?
If you have solved this issue could you share what you did to get it working?

Thank you


(Jason) #14

Just curious, is the DIP switched to D2/D3 on the ST shield? I had a similar issue with inactivity a few months back working on this Smart Sprinkler. Once I moved the switch to D2/D3 all my issues were resolved.


(Andrew Arace) #15

Well, I’m glad that someone else is having the exact problems I am.
My shield is just never receiving data that I can tell. I followed the same steps - I also tried the device type On/Off (not the one with “(example)”) and can’t receive anything on my arduino duemilenove’s serial output.

So, is this $35 product completely bricked?


(Andrew Arace) #16

Following up, it looks like it may not be compatible with the older ATMega168 based Duemilanove

Could someone confirm and update the documentation for the shield?