Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define RXD2 26
- #define TXD2 27
- #define PKEY 14
- #define RST 12
- #define TINY_GSM_MODEM_SIM7600
- #define BLYNK_TEMPLATE_ID "TMPLE1aPZJfE"
- #define BLYNK_TEMPLATE_NAME "Solar_Tracker"
- #define BLYNK_AUTH_TOKEN "aoZ95-IDwV16oVP3N9TChD36QmmPWMRz"
- #define BLYNK_PRINT Serial
- #define SerialMon Serial
- #define SerialAT Serial2
- #include <TinyGsmClient.h>
- #include <BlynkSimpleTinyGSM.h>
- TinyGsm modem(SerialAT);
- unsigned long cur_time_res, old_time_res;
- unsigned long cur_time, old_time;
- bool hold = 0;
- #define TINY_GSM_MODEM_SIM7600
- #if !defined(TINY_GSM_RX_BUFFER)
- #define TINY_GSM_RX_BUFFER 650
- #endif
- #define TINY_GSM_DEBUG SerialMon
- // set GSM PIN, if any
- #define GSM_PIN ""
- // Your GPRS credentials, if any
- char apn[] = "Internet";
- char user[] = "";
- char pass[] = "";
- int counter = 0;
- int count_con = 0;
- #define WATCHDOG_TIMEOUT_S 20 // restart jika tidak ada respon 5detik
- hw_timer_t * watchDogTimer = NULL;
- void IRAM_ATTR watchDogInterrupt() {
- Serial.println("reboot");
- ESP.restart();
- }
- void watchDogRefresh()
- {
- timerWrite(watchDogTimer, 0); //reset timer (feed watchdog)
- }
- void setup() {
- // put your setup code here, to run once:
- delay(100);
- Serial.begin(115200);
- SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
- pinMode(RST, OUTPUT);
- pinMode(PKEY, OUTPUT);
- digitalWrite(PKEY, LOW);
- digitalWrite(RST, LOW);
- delay(1000);
- digitalWrite(PKEY, HIGH);
- digitalWrite(RST, HIGH);
- delay(1000);
- digitalWrite(PKEY, LOW);
- digitalWrite(RST, LOW);
- delay(1000);
- SerialMon.println("Initializing modem...");
- modem.restart();
- String modemInfo = modem.getModemInfo();
- Serial.print("Modem Info: ");
- Serial.println(modemInfo);
- Blynk.begin(BLYNK_AUTH_TOKEN, modem, apn, user, pass);
- delay(100);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- Blynk.run();
- cur_time_res = millis();
- if (cur_time_res - old_time_res >= 1000) {
- watchDogRefresh();
- old_time_res = millis();
- }
- cur_time = millis();
- if (cur_time - old_time >= 4000) {
- //baca_pzem();
- Blynk.virtualWrite(V3, counter);
- counter ++;
- if (counter == 1500) {
- counter = 0;
- }
- bool check_con = Blynk.connected();
- Serial.print("connected: " );
- Serial.println(check_con);
- if (check_con == false) {
- count_con++;
- if (count_con == 20) {
- Serial.print("disconnect: ");
- Serial.println(count_con);
- reset_sim();
- wakeup_sim();
- }
- }
- old_time = millis();
- }
- }
- void reset_sim() {
- digitalWrite(RST, HIGH);
- }
- void wakeup_sim() {
- SerialMon.println("wakeup sim7600");
- digitalWrite(PKEY, LOW);
- digitalWrite(RST, LOW);
- delay(1000);
- digitalWrite(PKEY, HIGH);
- digitalWrite(RST, HIGH);
- delay(1000);
- digitalWrite(PKEY, LOW);
- digitalWrite(RST, LOW);
- delay(1000);
- wRespon(15000);
- }
- void wRespon(long waktu) {
- cur_time_res = millis();
- old_time_res = cur_time_res;
- while (cur_time_res - old_time_res < waktu ) {
- cur_time_res = millis();
- while (SerialAT.available() > 0) {
- SerialMon.print(SerialAT.readString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement