Ahmad Fahad
/
Geofence_sender
Yeah it works!
Fork of Geofence_sender by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include <RF22.h> 00003 #include <RF22ReliableDatagram.h> 00004 #include <GPS.h> 00005 00006 // Sample programm for ReliableDatagramm Sending 00007 // Uses address 1 and sends to RF22 with address 2 00008 // See notebook http://mbed.org/users/charly/notebook/rfm22/ for connecting RFM22 to mbed 00009 DigitalOut myled(LED1); 00010 Serial pc(USBTX, USBRX); 00011 GPS af(PB_10, PB_11); 00012 //RF22ReliableDatagram (uint8_t thisAddress, PinName slaveSelectPin, PinName mosi, PinName miso, PinName sclk, PinName interrupt) 00013 RF22ReliableDatagram rf22(0,PB_6,PA_7,PA_6,PA_5,PA_10); 00014 00015 float frequency = 433; // frequency 00016 00017 const uint8_t sender_adress = 1; // address of sender 00018 const uint8_t receiver_adress =2; // address of receiver 00019 00020 00021 // send messages forever 00022 int send_loop() { 00023 uint8_t data[32] = ""; 00024 int flagcheck1=0; 00025 00026 while (flagcheck1==0) { 00027 00028 if(af.sample()==1) 00029 { 00030 float latitude=af.latitude; 00031 float longitude=af.longitude; 00032 sprintf((char*)data,"%f,%f",latitude,longitude); 00033 pc.printf("%f, %f",latitude,longitude); 00034 //sendtoWait(uint8_t* buf, uint8_t len, uint8_t address); 00035 pc.printf("\n\rStart sending ... "); 00036 if (rf22.sendtoWait(data, sizeof(data), receiver_adress)) { 00037 pc.printf("Send to %i ACK: >>%s<< ", receiver_adress,(char*)data); 00038 } 00039 else { 00040 pc.printf("Send to %i NOTACK: >>%s<< ", receiver_adress,(char*)data); 00041 } 00042 pc.printf("sleeping 2 seconds... "); 00043 flagcheck1=1; 00044 wait(1); 00045 } 00046 else 00047 { 00048 myled=1; 00049 wait(0.5); 00050 myled=0; 00051 wait(0.5); 00052 } // Wait 2 Seconds 00053 } 00054 } 00055 void rfcheck() 00056 { 00057 pc.printf("\n\rConnected to mbed\n\r"); 00058 00059 pc.printf ("RF22-Test-Reliable-Send V1.0\n\r"); 00060 00061 // initialize the device 00062 if (!rf22.init()) 00063 pc.printf("RF22 init failed\n\r"); 00064 00065 // set to 19.2 KB 00066 if (!rf22.setModemConfig(RF22::GFSK_Rb19_2Fd9_6)) 00067 pc.printf("setModemConfig failed"); 00068 00069 if (!rf22.setFrequency(frequency)) 00070 pc.printf("setFrequency failed"); 00071 00072 // Code for sending 00073 pc.printf("I am sending with address %i to adress %i ...\n\r",sender_adress,receiver_adress ); 00074 rf22.setThisAddress(sender_adress); // sender-adress 00075 00076 } 00077 int main() { 00078 00079 pc.baud(9600); 00080 rfcheck(); 00081 00082 send_loop(); // start sending 00083 } 00084
Generated on Fri Jul 15 2022 01:19:00 by 1.7.2