WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

droneCell

Adds support for the DroneCell - currently limited to text messaging.
This device is only supported in WebbotLib Version 2.03 or higher.
 
dronecell.jpg
When you use this device in Project Designer you will need to give it some power, as well as specifying the UART for transmitting and receiving data. The only other compulsory pin is the RESET pin which is used to initialise the device, The remaining pins are all optional input pins to the micro controller:-
Although the DroneCell is capable of much more - the only features currently supported by WebbotLib are to receive and send SMS messages when there is a signal. You will need to provide an appropriate SIM card for the telephone network of your choice.
One other thing you will need to define, in Project Designer, is the SMSC (SMS Message Centre) number for your network provider. Project Designer gives a list for some combinations of operator and the country you are in but is not exhaustive and I cannot guarantee that they are, or will always be, correct. If you are using the SIM card from your phone then first try going in to Phone Settings, Network Settings, Configuration etc until you can find the appropriate SMSC number. This number is in international format ie a '+' followed by the country code, then the number with the leading '0' removed.
Messages sent and received through WebbotLib always go via the SIM card ie received messages are received directly to the SIM and then WebbotLib reads them out; and sent messages are first written to the SIM card and are then sent in the background as and when you have a signal. Note that if you have problems sending lots of SMS messages one after the other then it may be that the SIM card is full - mine can only queue up a total of 10 messages 'in and out'.
The message queue, signal strength, operator name (eg 'T-Mobile' etc) are processed by WebbotLib in the background.
Obviously sending an SMS Message may have financial implications - WebbotLib makes no warranty for the open source libraries. So if you write code that sends 100s of messagess and you get a big bill - then its not my fault !
Here is some example code:-
Showing the signal strength and network operator name
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
cout.print_P( PSTR("Signal=") );
    cout.print(droneCell.getSignalStrength());
    cout.print_P( PSTR(" Operator=") ).print(droneCell.getOperator());
}
Sending an SMS Message
Sending a message is not necessarily guaranteed to happen - the DroneCell may be doing something else - or you may have accidentally switched it off - there are lots of reasons! So there are lots of 'if' statements to keep track of where we are. Just add this inside your appControl logic:-
// Try to set up for sending a text message to a given number
// I've changed the destination number to contain 'x' characters so you
// dont get to see my work mobile number !
if(droneCell.initSMS("+44789xxxx638")){
    // Ok the drone cell is free so put body of message
    // You can use any of the output stream print commands
    droneCell.print_P( PSTR("Hello World") );
    // Now try to send it - may still fail eg SIM card is full or device not connected
    boolean sent = droneCell.sendSMS();
    // We now know if the message has been sent or not so your program
    // can decide what to do !
}
Auto Responder
Here is a neat way to test your code. This will listen for incoming texts from another telephone number and will then reply to the same number by prefixing the message with 'Got ya'.
ie send a message saying 'WebbotLib is cool' and get a reply of 'Got ya: WebbotLib is cool'.
// See if there is a received text
uint8_t msgNo = droneCell.messageWaiting();
if(msgNo){
    // Yes there is - print out which SIM card slot
    cout.print_P( PSTR("Message#") ).print(msgNo).println();
    // Try to read the message in that slot 
    if(droneCell.readMessage(msgNo)){
        // we have read it - so dump it out
        cout.print_P( PSTR("Msg from '") );
        cout.print(droneCell.getMessagePhoneNumber());
        cout.print_P( PSTR("':") ).print(droneCell.getMessageBody()).println();
 
        // If from my work mobile
        if(strcmp_P(droneCell.getMessagePhoneNumber(),PSTR("+44789xxxx638"))==0){
            // reply
            if(droneCell.initSMS(droneCell.getMessagePhoneNumber())){
                // put body of message
                droneCell << "Got ya: " << droneCell.getMessageBody();
                // Try to send the reply
                if(droneCell.sendSMS()){
                    // Success so delete the original message
                    while(!droneCell.deleteMessage(msgNo)){
                        cout << "Delete failed\n";
                    }
                    cout << "OK Delete msg\n";
                }else{
                    // Couldn't send the reply - since we haven't deleted
                    // the original message then we will reply again later
                    cout << "Send reply failed\n";
                }
            }
        }
    }
}
Function Summary

Valid XHTML 1.0 Transitional