Advertisement
mikroavr

blynk sample

Jan 19th, 2019
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. //#define BLYNK_PRINT Serial
  2.  
  3. // Select your modem:
  4. #define TINY_GSM_MODEM_SIM800
  5. //#define TINY_GSM_MODEM_SIM900
  6. //#define TINY_GSM_MODEM_M590
  7. //#define TINY_GSM_MODEM_A6
  8.  
  9. // Default heartbeat interval for GSM is 60
  10. // If you want override this value, uncomment and set this option:
  11. //#define BLYNK_HEARTBEAT 30
  12.  
  13. #include <TinyGsmClient.h>
  14. #include <BlynkSimpleSIM800.h>
  15.  
  16. // You should get Auth Token in the Blynk App.
  17. // Go to the Project Settings (nut icon).
  18. char auth[] = "YourAuthBlynk";
  19.  
  20. // Your GPRS credentials
  21. // Leave empty, if missing user or pass
  22. char apn[]  = "Internet";
  23. char user[] = "";
  24. char pass[] = "";
  25.  
  26.  
  27. int voltage1, voltage2;
  28. unsigned long voltage3;
  29. String pesan;
  30.  
  31. // Hardware Serial on Mega, Leonardo, Micro
  32. //#define SerialAT Serial1
  33.  
  34. // or Software Serial on Uno, Nano
  35. #include <SoftwareSerial.h>
  36. SoftwareSerial SerialAT(A2, A3); // RX, TX
  37. TinyGsm modem(SerialAT);
  38. BlynkTimer timer;
  39. WidgetTerminal terminal(V2);
  40. BLYNK_WRITE(V2);
  41.  
  42. void setup()
  43. {
  44.   // Debug console
  45.   Serial.begin(9600);
  46.  
  47.   delay(10);
  48.  
  49.   // Set GSM module baud rate
  50.   SerialAT.begin(38400);
  51.   delay(3000);
  52.  
  53.   // Restart takes quite some time
  54.   // To skip it, call init() instead of restart()
  55.   Serial.println("Initializing modem...");
  56.   modem.restart();
  57.  
  58.   // Unlock your SIM card with a PIN
  59.   //modem.simUnlock("1234");
  60.  
  61.    Blynk.begin(auth, modem, apn, user, pass);
  62.    timer.setInterval(1000L, sendUptime);
  63. }
  64.  
  65. void loop()
  66. {
  67.   Blynk.run();
  68.   timer.run();
  69. }
  70.  
  71. void sendUptime(){
  72.   voltage1 ++;
  73.   voltage3 ++;
  74.   voltage2 = voltage1;
  75.   pesan = String("Terjual: ") + voltage3;
  76.  
  77.   if ( voltage1 == 100)voltage1 = 0;
  78.   if ( voltage3 == 1000000) voltage3 = 0;
  79.   Blynk.virtualWrite(V0, voltage1);
  80.   Blynk.virtualWrite(V1, voltage2);
  81.  
  82.   terminal.println(pesan);
  83.   terminal.flush();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement