Advertisement
tobeedelafuente

meeo-fona-gps

Feb 23rd, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 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. float lat = 0;
  22. float lon = 0;
  23.  
  24. void setup() {
  25.   Serial.begin(115200);
  26.   SerialAT.begin(4800);
  27.  
  28.   Serial.println("Initializing...");
  29.  
  30.   if (!modem.restart()) {
  31.     Serial.println("GSM Failed");
  32.     while (true);
  33.   }
  34.  
  35.   Serial.println("GSM connected");
  36.   modem.enableGPS();
  37.  
  38.   if (!modem.waitForNetwork()) {
  39.     while (true);
  40.   }
  41.   Serial.println("Network detected");
  42.  
  43.   if (!modem.gprsConnect(apn, user, pass)) {
  44.     while (true);
  45.   }
  46.   Serial.println("GPRS connected");
  47.  
  48.   Meeo.setEventHandler(meeoEventHandler);
  49.   Meeo.begin(nameSpace, accessKey, client);
  50. }
  51.  
  52. void loop() {
  53.   Meeo.run();
  54.  
  55.   if (millis() - payloadMillis >= 1000) {
  56.     payloadMillis = millis();
  57.  
  58.     modem.getGPS(&lat, &lon, NULL, NULL, NULL, NULL);
  59.     payload = String(lat, 6) + "," + String(lon, 6);
  60.  
  61.     Meeo.publish(channel, payload);
  62.   }
  63. }
  64.  
  65. void meeoEventHandler(MeeoEventType event) {
  66.   switch (event) {
  67.     case MQ_DISCONNECTED:
  68.       Serial.println("Disconnected from MQTT Server");
  69.       break;
  70.     case MQ_CONNECTED:
  71.       Serial.println("Connected from MQTT Server");
  72.       break;
  73.     default:
  74.       break;
  75.   }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement