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 pin_en 13
- #define SerialMon Serial
- #define SerialAT Serial2
- int ledState = LOW;
- const int ledPin = 15;
- int counter = 0;
- unsigned long cur_time_led, old_time_led;
- 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
- const char apn[] = "Internet";
- const char gprsUser[] = "";
- const char gprsPass[] = "";
- const char server[] = "vsh.pp.ua";
- const char resource[] = "/TinyGSM/logo.txt";
- const int port = 80;
- #include <TinyGsmClient.h>
- #include <ArduinoHttpClient.h>
- #ifdef DUMP_AT_COMMANDS
- #include <StreamDebugger.h>
- StreamDebugger debugger(SerialAT, SerialMon);
- TinyGsm modem(debugger);
- #else
- TinyGsm modem(SerialAT);
- #endif
- TinyGsmClient client(modem);
- HttpClient http(client, server, port);
- void setup() {
- // put your setup code here, to run once:
- SerialMon.begin(115200);
- SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
- delay(250);
- SerialMon.println("test at mulai");
- pinMode(ledPin, OUTPUT);
- pinMode(RST, OUTPUT);
- pinMode(PKEY, OUTPUT);
- pinMode(pin_en, 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();
- wRespon(5000);
- if(res_cmd("AT","OK",5000)){
- Serial.println("sim7600 on");
- }else{
- Serial.println("sim7600 nok");
- digitalWrite(pin_en,HIGH);delay(1000);
- digitalWrite(pin_en,LOW); delay(1000);
- ESP.restart();
- }
- //bool res = modem.sendSMS("082165062273", "bismillaah, ini dari saya,monitoring smart farming , testing ya");
- //DBG("SMS:", res ? "OK" : "fail");
- /*SerialAT.println("AT");
- wRespon(1000);
- SerialAT.println("AT+IPREX?");
- wRespon(1000);
- SerialAT.println("AT+IPREX=115200");
- wRespon(1000);
- SerialAT.println("AT&W");
- wRespon(1000);22,21m
- SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
- */
- }
- void loop() {
- // put your main code here, to run repeatedly:
- SerialMon.println("SEND AT");
- cur_time_led = millis();
- if (cur_time_led - old_time_led >= 1000) {
- counter++;
- switch (counter) {
- case 1:
- send_at("AT+CPIN?");
- break;
- case 2:
- send_at("AT+CSQ");
- break;
- case 3:
- send_at("AT+CPSI?");
- break;
- case 4:
- send_at("ATI");
- break;
- case 5:
- send_at("AT+IPR?");
- counter = 0;
- break;
- }
- if (ledState == LOW) {
- ledState = HIGH;
- } else {
- ledState = LOW;
- }
- digitalWrite(ledPin, ledState);
- old_time_led = cur_time_led;
- }
- }
- void send_at(char *_command) {
- SerialAT.println(_command);
- wRespon(1000);
- }
- void wRespon(long waktu) {
- cur_time = millis();
- old_time = cur_time;
- while (cur_time - old_time < waktu ) {
- cur_time = millis();
- while (SerialAT.available() > 0) {
- SerialMon.print(SerialAT.readString());
- }
- }
- }
- 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);
- }
- int8_t res_cmd(char* ATcommand, char* expected_answer, unsigned int timeout) {
- uint8_t x = 0, answer = 0;
- char response[100];
- unsigned long prevMillis;
- memset(response, '\0', 100);
- delay(100);
- while (SerialAT.available() > 0)SerialAT.read();
- SerialAT.println(ATcommand);
- prevMillis = millis();
- do {
- if (SerialAT.available() != 0) {
- response[x] = SerialAT.read();
- x++;
- if (strstr(response, expected_answer) != NULL) {
- answer = 1;
- }
- }
- } while ((answer == 0) && ((millis() - prevMillis) < timeout));
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement