Another person having trouble getting started with Arduino Mega

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 :slight_smile:

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!

Sorry about the formatting of the #define and #include statements in my Arduino code snippet.

Let me supply some more information. For some reason, I suddenly started getting some response when I send a message from the Arduino to the SmartThings hub though I don’t understand it.

When I’m watching the log window for my device driver and I type anything into the Arduino serial monitor where my Arduino code will send it to the SmarThings hub I see the follow:

83aa6814-8598-4bc1-b408-f57b810ce9df
6:49:38 PM:
debug
Unknown Command Received

83aa6814-8598-4bc1-b408-f57b810ce9df
6:49:38 PM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A70696E67'

No matter what I type in, I get the exact same thing to show up in the log. I’ve seen reference in the documentation to “catchall” but I’ve never found any explanation of what they are, how to deal with them, etc

Hopefully someone has seen this before and can shed some light on what I have going on and how to address the issue.

Thanks in advance for the help

A catchall is a “raw” message type. That particular message is a “ping” from the shield. Meaning the shield is able to send the ASCII message “ping” (hex 0A70696E67) from the shield and have it hit your device handler. You get the ping message as part of the debug mode which you have enabled.

So this means messages can flow up, but something is getting borked when you are sending the message. How often are you sending the message?

P.S. I also fixed your formatting for you :blush:

Thanks Andrew!

Right now I’m just sending a message from the Arduino to the SmartThings hub when I type it into the Arduino Console. When I’m testing that happens every 10, 15 seconds or even minutes apart. There is no automated traffic that would be overloading things.

Thanks again for your help!

are you sending the messages as strings?

Thanks for getting back to me Andrew.

Yes I am sending the messages as strings.

what happens when you try to send static messages instead of typing them in the serial monitor. Like smartthing.send("on");

Andrew

I added the following to the end of the setup block in my Arduino code:
smartthing.send(“tester string”);

In the SmartThings Inteface Console window I get the following. Note - the “Unknown Command Received” messages are generated by my driver when it gets something it doesn’t know how to parse.

Thanks again for your help!

9:00:02 AM:
debug
Unknown Command Received

9:00:02 AM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A70696E67'


9:00:01 AM:
debug
Unknown Command Received


9:00:01 AM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A74657374657220737472696E67'


8:59:45 AM:
debug
Unknown Command Received


8:59:45 AM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A70696E67'

0A70696E67 = “ping”

0A74657374657220737472696E67 = “tester string”

So its executing correctly, but something about the way you are sending it while you type is not being sent correctly.

Thanks Andrew. But this leaves me very confused. In my arduino code I’m just monitoring the serial port for input, concatenating the characters together into a string, and sending it when a CR is typed. I’m using the exact same call to send the string as I used to send the “tester string” that worked.

The only difference I can see is that when I’m sending the string entered from the serial monitor it has a trailing carriage return. I’ll try omitting that to see if it makes a difference.

Here is party of my arduino code in case you see anything else that would cause an issue.

Thanks again for your help

Jay


SmartThingsCallout_t messageCallout;
SmartThings smartthing(PIN_THING_RX, PIN_THING_TX, messageCallout);

// Global variables
String command;
char inByte;

void setup()
{
// setup default state of global variables
isDebugEnabled = true;
command = “”;
inByte = 0;

if (isDebugEnabled)
{
    Serial.begin(9600);
    Serial.println("Setup Complete");
}

smartthing.send("tester string");

}

void loop()
{
// run smartthing logic
smartthing.run();

if (isDebugEnabled)
{
    if (Serial.available() > 0) 
    {
        inByte = Serial.read();

        // 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);
        }
    }

    //Process command received from the serial monitor
    if (inByte == CR) 
    {
        command.concat(inByte);

        //send the command to smartthings
        smartthing.send(command);
        command = "";
    }
    inByte = 0;
}    

}

I removed the carriage return when I send a string I’ve entered in the Arduino serial monitor and I think it is now making it to the SmartThings hub properly. :slight_smile:

I typed in the text “tester” and I get the following in the console

9:25:00 AM:
debug
Unknown Command Received

9:25:00 AM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A746573746572'


9:24:59 AM:
debug
Unknown Command Received


9:24:59 AM:
debug
Parsing 'catchall: 0104 0000 01 01 0140 00 EB7B 00 00 0000 0A 00 0A70696E67'

and 746573746572 is the ascii codes for tester.

PROGRESS!!

While that seems to have solved the issue of getting a message from the Arduino to my SmartThings driver, I’m now having an issue parsing the text in the driver. Here is the code in my driver

def parse(String description) 
{
    log.debug "Parsing '${description}'"
    if (description.startsWith("cmd1="))
    {
        if (description.substring(5) == "1")
        {
            log.debug "Parser Result - cmd1=1"
            //do something
        }
        else
        {
            log.debug "Parser Result - cmd1=0"
            //do something
        }
    }
    else
    {
        log.debug "Unknown Command Received"
    }
}

When I type in cmd1=1 I still get “Unknown Command Received”

I’m still just not sure about what the Catchall statement in the SmartThings console is completely telling me and why it is generated when my driver parsing code says

log.debug "Parsing '${description}'"

Shouldn’t just the text I entered in the Arduino be coming through as the description string or is the description string always going to include the catchall text before my actual string and I just need to work around that in my parsing. By chance is the catchall text generated because isDebugEnabled is set to true on the Arduino?

Thanks again for all your help

Just wanted to bump this thead to see if anyone has any info on the format of strings that come in from the thingshield. It has been several days and I didn’t want the thread to get lost as I’m still looking for an answer

Thanks in advance for the help

@jbasen I’m the worst. So long without an answer. :frowning:

So the catchall message is the formatted version of the raw ZigBee message. It is always going to come in as a hex value of the ASCII string. You will have to use the zigbee.parse to get that out. Check out the On/Off Shield in the example list.

Thanks Andrew. That makes sense.