Advertisement
tobeedelafuente

meeo-fona-sms

Feb 23rd, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. #define TINY_GSM_MODEM_SIM808
  2.  
  3. #include <Meeo.h>
  4. #include <TinyGsmClient.h>
  5. #include <SoftwareSerial.h>
  6.  
  7. SoftwareSerial SerialAT(2, 3); // RX, TX
  8. TinyGsm modem(SerialAT);
  9. TinyGsmClient client(modem);
  10.  
  11. const char apn[]  = "http.globe.com.ph";
  12. const char user[] = "";
  13. const char pass[] = "";
  14.  
  15. String nameSpace = "my_namespace";
  16. String accessKey = "my_access_key";
  17. String ssid = "MyWiFi";
  18. String pass = "qwerty123";
  19. String channel = "my-channel";
  20.  
  21. void setup() {
  22.   Serial.begin(115200);
  23.   SerialAT.begin(4800);
  24.  
  25.   Serial.println("Initializing...");
  26.  
  27.   if (!modem.restart()) {
  28.     Serial.println("GSM Failed");
  29.     while (true);
  30.   }
  31.  
  32.   Serial.println("GSM connected");
  33.  
  34.   if (!modem.waitForNetwork()) {
  35.     while (true);
  36.   }
  37.   Serial.println("Network detected");
  38.  
  39.   if (!modem.gprsConnect(apn, user, pass)) {
  40.     while (true);
  41.   }
  42.   Serial.println("GPRS connected");
  43.  
  44.   Meeo.setEventHandler(meeoEventHandler);
  45.   Meeo.setDataReceivedHandler(meeoDataHandler);
  46.   Meeo.begin(nameSpace, accessKey, client);
  47. }
  48.  
  49. void loop() {
  50.   Meeo.run();
  51. }
  52.  
  53. void meeoDataHandler(String topic, String payload) {
  54.   Serial.print(topic);
  55.   Serial.print(": ");
  56.   Serial.println(payload);
  57.  
  58.   if (Meeo.isChannelMatched(topic, channel)) {
  59.     String temp = payload;
  60.     String number = String(strtok(&temp[0], ","));
  61.     String message = String(strtok(NULL, ","));
  62.     modem.sendSMS(number, message);
  63.   }
  64. }
  65.  
  66. void meeoEventHandler(MeeoEventType event) {
  67.   switch (event) {
  68.     case MQ_DISCONNECTED:
  69.       Serial.println("Disconnected from MQTT Server");
  70.       break;
  71.     case MQ_CONNECTED:
  72.       Serial.println("Connected from MQTT Server");
  73.       Meeo.subscribe(channel);
  74.       break;
  75.     default:
  76.       break;
  77.   }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement