GSM_M6315.ino 827 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Description: Send AT command to get current signal quality.
  3. */
  4. #include <M5Stack.h>
  5. void IotWriteCommand(char cmd[],char date[]){
  6. char buf[256] = {0};
  7. if(cmd == NULL)
  8. sprintf(buf,"AT\r\n");
  9. else if(date == NULL)
  10. sprintf(buf,"AT+%s\r\n",cmd);
  11. else
  12. sprintf(buf,"AT+%s=%s\r\n",cmd,date);
  13. Serial2.write(buf);
  14. }
  15. //AT+CSQ=?
  16. void get_time(void){
  17. IotWriteCommand("CSQ=?",NULL);
  18. while(Serial2.available()){
  19. uint8_t ch = Serial2.read();
  20. Serial.write(ch);
  21. M5.Lcd.write(ch);
  22. }
  23. }
  24. void setup() {
  25. M5.begin();
  26. M5.Power.begin();
  27. Serial.begin(115200);
  28. Serial2.begin(115200, SERIAL_8N1, 16, 17);
  29. pinMode(5, OUTPUT);
  30. digitalWrite(5, 1);
  31. }
  32. void loop() {
  33. if(M5.BtnA.wasReleased()){
  34. M5.Lcd.fillScreen(TFT_BLACK);
  35. M5.Lcd.setCursor(60,80,2);
  36. get_time();
  37. }
  38. M5.update();
  39. }