Advertisement
193030

ARDUINO_GS_v04_2301_successfull_confirmation

Sep 4th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. // Confirmation message received
  2.  
  3. /*
  4. 433 MHz RF Module Transmitter Demonstration 1
  5. RF-Xmit-Demo-1.ino
  6. Demonstrates 433 MHz RF Transmitter Module
  7. Use with Receiver Demonstration 1
  8. //
  9. DroneBot Workshop 2018
  10. https://dronebotworkshop.com
  11. */
  12. // Arduino data pin - 12, changed to D5
  13. // Include RadioHead Amplitude Shift Keying Library
  14. #include <RH_ASK.h>
  15. // Include dependant SPI Library
  16. #include <SPI.h>
  17. #define arraySize 4
  18. #define BUFF_LENGTH 15
  19. uint8_t buf[BUFF_LENGTH];
  20. unsigned long currentMillis;
  21. unsigned long previousMillis;
  22. char *msgArr[4] = {"42345617891234567891234567891234567891234567891234567890", "5234567891234567891234567891234567891234567891234567890", "6234567891234567891234567891234567891234567891234567890", "7234567891234567891234567891234567891234567891234567890"};
  23. //char *msg = "msgfromgroundstation1234";
  24. char *msg = "AA|03|a12345|aa";
  25. char *confirmationString = "AA|03|a12345|aa";
  26. const int intervalCommunication = 800;
  27. int flagReceived = 0;
  28. int flagSent = 0;
  29. //s
  30. uint8_t timesSent = 0;
  31. int timesSending = 1;
  32. int flagConfirmWait = 0;
  33. uint8_t buflen;
  34. String bufferString = "";
  35. // Create Amplitude Shift Keying Object
  36. RH_ASK rf_driver;
  37. int loopExecute = 0;
  38. String tempConfirm;
  39. void setup()
  40. {
  41. // Initialize ASK Object
  42. rf_driver.init();
  43. Serial.begin(9600);
  44. Serial.println("serial is opening transmitter");
  45.  
  46. }
  47.  
  48. void sendNTimes(int times, char *tempMsg)
  49. {
  50. Serial.print("Sending");
  51. Serial.println(timesSent);
  52. for(int i =0; i<times; i++)
  53. {
  54. rf_driver.send((uint8_t *)tempMsg,strlen(tempMsg));
  55. rf_driver.waitPacketSent();
  56. delay(10);
  57. }
  58. }
  59.  
  60. void sendMsgToSatellite()
  61. {
  62. buflen = sizeof(buf);
  63. if(flagConfirmWait == 0)
  64. {
  65. if(timesSent++<timesSending)
  66. {
  67. sendNTimes(3,msg);
  68. flagConfirmWait = 1;
  69.  
  70. }
  71. // delay(800);
  72. }
  73.  
  74. if(flagConfirmWait == 1)
  75. {
  76. if (rf_driver.recv(buf, &buflen))
  77. {
  78. flagConfirmWait = 0;
  79. Serial.print("Confirmation msg Received:");
  80. bufferString = (char*)buf;
  81. bufferString = bufferString.substring(0, BUFF_LENGTH-1);
  82. Serial.println(bufferString);
  83. // Replace tempConfirm with the sending string
  84. tempConfirm = (char*)confirmationString;
  85. tempConfirm = tempConfirm.substring(0, BUFF_LENGTH-1);
  86. // Serial.print("Temp string:");
  87. // Serial.println(tempConfirm);
  88.  
  89. if(bufferString == tempConfirm)
  90. {
  91. Serial.println("Successfull event. String matches.");
  92. }
  93. else
  94. {
  95. Serial.println("Unsuccessfull event. String doesn't match.");
  96.  
  97. }
  98. loopExecute++;
  99. delay(100);
  100. }
  101. }
  102. }
  103.  
  104. void loop()
  105. {
  106. currentMillis = millis();
  107. if(loopExecute == 0){
  108. sendMsgToSatellite();
  109.  
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement