SMS C++
Collaboration diagram for SMS C++:

Namespaces

 dpySms
 Deepsy SMS namespace that includes the different enums, structs or method signatures that should be used.
 

Classes

class  Sms
 Allows to interact with the SMS service. More...
 

Detailed Description

SMS API related documentation

A quick overview of basic SMS API capabilities and examples is given.
If you find SMS API useful and would like to know more details, please check out further sections of the SMS API documentation or contact the Deepsy platform team.

Examples

  • Creating a SMS object

    #include <dpy/smsApi.h>
    Sms smsManager;


  • Retrieve the SMS list
    An example of how to retrieve and read the list of SMS is provided:

    #include <dpy/smsApi.h>
    #include <iostream>
    void sms_list_handler(boost::system::error_code &error_code, std::map<std::string, dpySms::SmsInformation> &smsList)
    {
    if (error_code) {
    std::cout << "\rError : " << error_code.message() << std::endl;
    } else {
    std::cout << smsList.size() << (smsList.size() != 1 ? " sms have " : " sms has ") << "been received." << std::endl;
    if (smsList.size() > 0) {
    for (auto it = smsList.begin(); it != smsList.end(); it++) {
    char creation_date[15];
    strftime(creation_date, sizeof(creation_date), "%d/%m/%Y", &it->second.creationDate);
    char creation_time[15];
    strftime(creation_time, sizeof(creation_time), "%H:%M:%S ", &it->second.creationDate);
    std::cout << "\tSMS Id |\t " << it->first << std::endl;
    std::cout << "\tLocal source Id |\t " << it->second.localSourceId << std::endl;
    std::cout << "\tRemote source Id |\t " << it->second.remoteSourceId << std::endl;
    std::cout << "\tSMS content |\t " << it->second.content << std::endl;
    std::cout << "\tDirection |\t " << (it->second.direction == dpySms::SmsDirection::DIRECTION_OUTGOING ? "Outgoing" : "Incoming") << std::endl;
    std::cout << "\tCreation date [dd/mm/yyyy] |\t " << creation_date << " " << std::endl;
    std::cout << "\tCreation time [hh:mm:ss] |\t " << creation_time << " " << std::endl;
    std::cout << "\t------------------------------------------------------------------" << std::endl;
    std::cout << "\n";
    }
    }
    }
    }
    int main(int argc, char *argv[])
    {
    Sms sms;
    sms.asyncGetSmsList(sms_list_handler);
    sleep(30);
    }

  • Get list of sources and obtain its current status

    #include <dpy/smsApi.h>
    #include <iostream>
    volatile bool waiting = true;
    void source_status_event_handler(boost::system::error_code ec, std::string smssourceid, dpySms::SourceStatus event)
    {
    if (ec.value() == 0) {
    if (event == dpySms::ENABLED) {
    std::cout << "\rSms source status event: Source " << smssourceid << " " << "enabled." << std::endl;
    } else {
    std::cout << "\rSms source status event: Source " << smssourceid << " " << "disabled." << std::endl;
    }
    } else {
    std::cout << "\rError : " << ec.message() << std::endl;
    }
    }
    int main(int argc, char *argv[])
    {
    Sms sms;
    sms.monitorSourcesStatusEvents_S(source_status_event_handler);
    sleep(30);
    }

  • Subscribe to SMS source notifications
    The example below shows a example to be aware of changes in the SMS different sources status.

    #include <dpy/smsApi.h>
    #include <iostream>
    volatile bool waiting = true;
    void source_status_event_handler(boost::system::error_code ec, std::string smssourceid, dpySms::SourceStatus event)
    {
    if (ec.value() == 0) {
    if (event == dpySms::ENABLED) {
    std::cout << "\rSms source status event: Source " << smssourceid << " " << "enabled." << std::endl;
    } else {
    std::cout << "\rSms source status event: Source " << smssourceid << " " << "disabled." << std::endl;
    }
    } else {
    std::cout << "\rError : " << ec.message() << std::endl;
    }
    }
    int main(int argc, char *argv[])
    {
    Sms sms;
    sms.monitorSourcesStatusEvents_S(source_status_event_handler);
    sleep(30);
    }

  • Subscribe to SMS notifications : sms received, sms sent, sms deleted

    #include <dpy/smsApi.h>
    #include <iostream>
    void sms_notifications_handler(boost::system::error_code &error_code, dpySms::SmsNotifications notif, const std::string &sms_identifier, const std::string &sms_source)
    {
    if (error_code) {
    std::cout << "\rError : " << error_code.message() << std::endl;
    } else {
    using namespace dpySms;
    std::map<SmsNotifications, std::string> sms_notif_to_string_map;
    sms_notif_to_string_map[MODEM_NOT_WORKING] = "Modem not working";
    sms_notif_to_string_map[SMS_RECEIVED] = "SMS received";
    sms_notif_to_string_map[SMS_DELETED] = "SMS deleted";
    sms_notif_to_string_map[SMS_SENT] = "SMS sent";
    std::cout << "\rNotification: " << sms_notif_to_string_map[notif] << "\t";
    if (notif != MODEM_NOT_WORKING && !sms_identifier.empty()) {
    std::cout << "\rSource [" << sms_source << "] event [" << sms_notif_to_string_map[notif] << "] smsid is [" << sms_identifier << "]" << std::endl;
    } else {
    std::cout << "Could not obtain SMS identifier";
    }
    std::cout << "\n";
    }
    }
    int main(int argc, char *argv[])
    {
    Sms sms;
    sms.getSmsNotifications_S(sms_notifications_handler);
    sleep(30);
    }