Well my hardware arrived today and I’m finally getting to try and make all the code I’ve been writing to work. Fun, Fun, Fun
In the simulator when I execute one of my commands in my driver such as
def ModeOn()
{
log.debug "Executing 'ModeOn'"
zigbee.smartShield(text: "mode=1\n").format()
}
def ModeOff()
{
log.debug "Executing 'ModeOff'"
zigbee.smartShield(text: "mode=0\n").format()
}
I can see the text show up in my Arduino. Miracle of miracles it works.
However, when I try to go the other direction I’m not being successful. Here is a code snippet of what I’m doing in the Arduino. This code just takes text typed into the serial monitor and sends it to the SmartThings hub. Or at least that is what it is supposed to do :-).
#include <SoftwareSerial.h>
#include <SmartThings.h>
#define PIN_THING_RX 10
#define PIN_THING_TX 2
#define CR 13
SmartThingsCallout_t messageCallout; // call out function forward decalaration
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout); // constructor
// Global variables
String command; // String from Serial Monitor
char inByte; // Byte input from Serial Monitor Processor
bool isDebugEnabled; // enable or disable debug in this example
void setup()
{
// setup default state of global variables
isDebugEnabled = true; //true to enable diagnostics to serial monitor
command = "";
inByte = 0;
if (isDebugEnabled) //Is debug monitoring enabled?
{
Serial.begin(9600); // setup serial monitor with a baud rate of 9600
Serial.println("Setup Complete");
}
}
void loop()
{
// run smartthing logic
smartthing.run();
if (isDebugEnabled) //Is debug monitoring enabled?
{
if (Serial.available() > 0) //Are there any characters available for reading from the serial monitor
{
inByte = Serial.read(); //read 1 character
// only input if a letter, number, =,?,+ are typed!
if ((inByte >= 65 && inByte <= 90)
|| (inByte >=97 && inByte <=122)
|| (inByte >= 48 && inByte <=57)
|| inByte == 43
|| inByte == 61
|| inByte == 63)
{
command.concat(inByte); //add the character to the command string
}
}
//Process command received from the serial monitor
if (inByte == CR) //Is command terminated
{
command.concat(inByte); //add the CR character to the command
//send the command to smartthings
smartthing.send(command);
command = "";
}
inByte = 0;
}
}
Here is a snippet of the parsing in my device driver:
// parse events into attributes
def parse(String description)
{
log.debug "Parsing '${description}'"
if (description.startsWith("mode="))
{
if (description.substring(5) == "1")
{
log.debug "Parser Result - mode = 1"
def result = createEvent(name: "Mode", value: "on")
log.debug result?.descriptionText
return result
}
else
{
log.debug "Parser Result - mode = 0"
def result = createEvent(name: "Mode", value: "off")
log.debug result?.descriptionText
return result
}
}
else
{
log.debug "Unknown Command Received"
}
}
When I type mode=1 in the Arduino serial monitor I’m not seeing anything show up in the SmartThings monitor window. I’m not even seeing garbage show up which would be caught by a message “unknown command” being displayed.
Any thoughts or ideas on what I’m doing wrong that is keeping messages from traveling from the Arduino to the SmartThings Hub?
Almost forgot, I have a jumper between D3 and D10 and the switch on my ThingShield is set to D2,D3.
Thanks in advance for the help!