Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Sender.cpp
00001 #include "mbed.h" 00002 00003 // Code from TNode/TGateway @ Anarduino.com 00004 // NOTE: code sample was inspired from ideas gained from: https://github.com/aanon4/RFM69 00005 // 00006 // Sender - periodically send time(millis), radio temperature, RSSI to listener... 00007 // 2014 - anarduino.com 00008 // 00009 #include <RFM69.h> 00010 00011 #define GATEWAY_ID 1 00012 #define NODE_ID 9 // node ID 00013 #define NETWORKID 101 //the same on all nodes that talk to each other 00014 #define MSG_INTERVAL 100 00015 00016 // Uncomment only one of the following three to match radio frequency 00017 //#define FREQUENCY RF69_433MHZ 00018 //#define FREQUENCY RF69_868MHZ 00019 #define FREQUENCY RF69_915MHZ 00020 00021 #define IS_RFM69HW //NOTE: uncomment this ONLY for RFM69HW or RFM69HCW 00022 #define ENCRYPT_KEY "EncryptKey123456" // use same 16byte encryption key for all devices on net 00023 #define ACK_TIME 50 // max msec for ACK wait 00024 #define LED 9 // Anardino miniWireless has LEDs on D9 00025 #define SERIAL_BAUD 115200 00026 #define VERSION "1.0" 00027 00028 #define MSGBUFSIZE 64 // message buffersize, but for this demo we only use: 00029 // 1-byte NODEID + 4-bytes for time + 1-byte for temp in C + 2-bytes for vcc(mV) 00030 char msgBuf[MSGBUFSIZE]; 00031 00032 #ifdef TARGET_NUCLEO_F401RE 00033 Serial pc(USBTX, USBRX); 00034 DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 00035 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) 00036 RFM69 radio(D11,D12,D13,D10,D8); 00037 #elif defined(TARGET_NUCLEO_L152RE) 00038 Serial pc(USBTX, USBRX); 00039 DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 00040 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) 00041 RFM69 radio(D11,D12,D13,D10,D8); 00042 #elif defined(TARGET_LPC1114) 00043 Serial pc(USBTX, USBRX); 00044 DigitalOut myled(LED1); 00045 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) 00046 RFM69 radio(dp2,dp1,dp6,dp4,dp9); 00047 #elif defined(TARGET_LPC1768) 00048 Serial pc(USBTX, USBRX); 00049 DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 00050 //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) 00051 RFM69 radio(D11,D12,D13,D10,D8); // Seeedstudio Arch Pro 00052 //RFM69 radio(p5, p6, p7, p10, p9,p8) // Mbed 1768 ? 00053 #endif 00054 00055 bool promiscuousMode = false; // set 'true' to sniff all packets on the same network 00056 bool requestACK=false; 00057 Timer tmr; 00058 00059 main() { 00060 memset(msgBuf,0,sizeof(msgBuf)); 00061 int i=1; 00062 long l; 00063 tmr.start(); 00064 00065 pc.baud(SERIAL_BAUD); 00066 pc.printf("Sender %s startup at %d Mhz...\r\n",VERSION,(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915)); 00067 wait(2); 00068 radio.initialize(FREQUENCY, NODE_ID, NETWORKID); 00069 radio.encrypt(0); 00070 radio.setPowerLevel(20); 00071 radio.promiscuous(promiscuousMode); 00072 #ifdef IS_RFM69HW 00073 radio.setHighPower(); //uncomment #define ONLY if radio is of type: RFM69HW or RFM69HCW 00074 #endif 00075 msgBuf[0] = (uint8_t)NODE_ID; // load NODEID 00076 00077 while(1) { 00078 uint8_t tempC = radio.readTemperature(-1); // -1 = user cal factor, adjust for correct ambient 00079 uint8_t tempF = 1.8 * tempC + 32; // 9/5=1.8 00080 00081 l = tmr.read_ms(); // load time 00082 00083 sprintf((char*)msgBuf,"#%d, t=%Lu, temp=%dF, RSSI=%d ",i,l,tempF,radio.RSSI); 00084 if(radio.sendWithRetry((uint8_t)GATEWAY_ID, msgBuf,strlen(msgBuf),true)) 00085 pc.printf("Packet %d sent, Ack ok!\r\n",i++); 00086 else pc.printf("Packet %d sent, no Ack!\r\n",i++); 00087 wait_ms(MSG_INTERVAL); 00088 myled = !myled; 00089 } 00090 }
Generated on Mon Jul 18 2022 23:45:59 by
