Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Confirmation message received
- /*
- 433 MHz RF Module Transmitter Demonstration 1
- RF-Xmit-Demo-1.ino
- Demonstrates 433 MHz RF Transmitter Module
- Use with Receiver Demonstration 1
- //
- DroneBot Workshop 2018
- https://dronebotworkshop.com
- */
- // Arduino data pin - 12, changed to D5
- // Include RadioHead Amplitude Shift Keying Library
- #include <RH_ASK.h>
- // Include dependant SPI Library
- #include <SPI.h>
- #define arraySize 4
- #define BUFF_LENGTH 15
- uint8_t buf[BUFF_LENGTH];
- unsigned long currentMillis;
- unsigned long previousMillis;
- char *msgArr[4] = {"42345617891234567891234567891234567891234567891234567890", "5234567891234567891234567891234567891234567891234567890", "6234567891234567891234567891234567891234567891234567890", "7234567891234567891234567891234567891234567891234567890"};
- //char *msg = "msgfromgroundstation1234";
- char *msg = "AA|03|a12345|aa";
- char *confirmationString = "AA|03|a12345|aa";
- const int intervalCommunication = 800;
- int flagReceived = 0;
- int flagSent = 0;
- //s
- uint8_t timesSent = 0;
- int timesSending = 1;
- int flagConfirmWait = 0;
- uint8_t buflen;
- String bufferString = "";
- // Create Amplitude Shift Keying Object
- RH_ASK rf_driver;
- int loopExecute = 0;
- String tempConfirm;
- void setup()
- {
- // Initialize ASK Object
- rf_driver.init();
- Serial.begin(9600);
- Serial.println("serial is opening transmitter");
- }
- void sendNTimes(int times, char *tempMsg)
- {
- Serial.print("Sending");
- Serial.println(timesSent);
- for(int i =0; i<times; i++)
- {
- rf_driver.send((uint8_t *)tempMsg,strlen(tempMsg));
- rf_driver.waitPacketSent();
- delay(10);
- }
- }
- void sendMsgToSatellite()
- {
- buflen = sizeof(buf);
- if(flagConfirmWait == 0)
- {
- if(timesSent++<timesSending)
- {
- sendNTimes(3,msg);
- flagConfirmWait = 1;
- }
- // delay(800);
- }
- if(flagConfirmWait == 1)
- {
- if (rf_driver.recv(buf, &buflen))
- {
- flagConfirmWait = 0;
- Serial.print("Confirmation msg Received:");
- bufferString = (char*)buf;
- bufferString = bufferString.substring(0, BUFF_LENGTH-1);
- Serial.println(bufferString);
- // Replace tempConfirm with the sending string
- tempConfirm = (char*)confirmationString;
- tempConfirm = tempConfirm.substring(0, BUFF_LENGTH-1);
- // Serial.print("Temp string:");
- // Serial.println(tempConfirm);
- if(bufferString == tempConfirm)
- {
- Serial.println("Successfull event. String matches.");
- }
- else
- {
- Serial.println("Unsuccessfull event. String doesn't match.");
- }
- loopExecute++;
- delay(100);
- }
- }
- }
- void loop()
- {
- currentMillis = millis();
- if(loopExecute == 0){
- sendMsgToSatellite();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement