COM_SigFox.ino 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Description: Get device ID,PAC and Send "00FFEE" to Dongle.
  3. */
  4. #include <M5Stack.h>
  5. #define rxPin 16
  6. #define txPin 17
  7. //Set to 0 if you don't need to see the messages in the console
  8. #define DEBUG 1
  9. //Message buffer
  10. uint8_t msg[12];
  11. // the setup function runs once when you press reset or power the board
  12. void setup() {
  13. M5.begin();
  14. Serial2.begin(9600, SERIAL_8N1, rxPin, txPin);
  15. Serial.begin(115200);
  16. delay(2000);
  17. getID();
  18. delay(1000);
  19. getPAC();
  20. delay(1000);
  21. }
  22. // the loop function runs over and over again forever
  23. void loop() {
  24. Serial2.write("AT$SF=00FFEE\r\n");
  25. delay(60000);
  26. }
  27. //Get Sigfox ID
  28. String getID(){
  29. String id = "";
  30. char output;
  31. Serial2.write("AT$I=10\r\n");
  32. while(!Serial2.available()){
  33. }
  34. while(Serial2.available()){
  35. output = Serial2.read();
  36. id += output;
  37. delay(10);
  38. }
  39. if(DEBUG){
  40. Serial.println("Sigfox Device ID: ");
  41. Serial.println(id);
  42. M5.Lcd.println(id);
  43. }
  44. return id;
  45. }
  46. //Get PAC number
  47. String getPAC(){
  48. String pac = "";
  49. char output;
  50. Serial2.write("AT$I=11\r\n");
  51. while(!Serial2.available()){
  52. }
  53. while(Serial2.available()){
  54. output = Serial2.read();
  55. pac += output;
  56. delay(10);
  57. }
  58. if(DEBUG){
  59. Serial.println("PAC number: ");
  60. Serial.println(pac);
  61. M5.Lcd.println(pac);
  62. }
  63. return pac;
  64. }