Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define RXD2 26
- #define TXD2 25
- #define PKEY 7
- unsigned long cur_time, old_time;
- bool hold = 0;
- int baud_rate[] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800};
- #define TINY_GSM_MODEM_SIM800
- #define SerialMon Serial
- #define SerialAT Serial3
- #if !defined(TINY_GSM_RX_BUFFER)
- #define TINY_GSM_RX_BUFFER 650
- #endif
- #define TINY_GSM_DEBUG SerialMon
- #define GSM_PIN ""
- // Your GPRS credentials, if any
- const char apn[] = "Internet";
- const char gprsUser[] = "";
- const char gprsPass[] = "";
- // Server details
- const char _server[] = "iotles.com";
- 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:
- delay(1000);
- SerialMon.begin(115200);
- SerialAT.begin(9600);
- delay(1000);
- Serial.println("test at mulai");
- pinMode(PKEY, OUTPUT);
- pinMode(27, OUTPUT);
- digitalWrite(PKEY, HIGH);
- digitalWrite(27, HIGH);
- delay(1100);
- digitalWrite(PKEY, LOW);
- delay(1100);
- digitalWrite(PKEY, HIGH);
- String modemInfo = modem.getModemInfo();
- SerialMon.print("Modem Info: ");
- SerialMon.println(modemInfo);
- delay(1000);
- //change_baud();
- /*
- while (1) {
- for (int i = 0; i < 10; i++) {
- Serial.print(i);Serial.print(",");
- Serial.println(baud_rate[i]);
- SerialAT.begin(baud_rate[i], SERIAL_8N1, RXD2, TXD2);
- delay(500);
- send_at("AT+IPR?");
- delay(500);
- }
- }
- */
- }
- void loop() {
- // put your main code here, to run repeatedly:
- send_at("AT+GSN");
- digitalWrite(27, HIGH);
- send_at("AT+IPR?");
- digitalWrite(27, LOW);
- send_at("AT+CPIN?");
- digitalWrite(27, HIGH);
- send_at("AT+COPS?");
- digitalWrite(27, LOW);
- send_at("AT+CSQ");
- digitalWrite(27, HIGH);
- send_at("AT+CREG?");
- digitalWrite(27, LOW);
- }
- void change_baud() {
- send_at("AT");
- send_at("AT+IPR=?");
- Serial.println("change baut rate");
- send_at("AT+IPR=9600");
- send_at("AT&W");
- while (1) {
- send_at("AT");
- send_at("AT+IPR?");
- //send_at("AT&V");
- delay(1000);
- send_at("AT+COPS?");
- digitalWrite(27, LOW);
- send_at("AT+CSQ");
- digitalWrite(27, HIGH);
- send_at("AT+GSN");
- digitalWrite(27, HIGH);
- }
- }
- 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) {
- Serial.print(SerialAT.readString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement