void changeChannel(byte newC) { radio.stopListening(); radio.setChannel(newC); radio.startListening(); }
void trans() { Serial.println("Enter a msg (max 32 Characters)"); while(!Serial.available()); delay(32); // for collection char tx[32]; for(int j=0;j<32;j++) { tx[j]=Serial.read(); if(tx[j]==(char)-1) // to avoid writing unkown char in spaces { tx[j]='\0'; goto loop1; } } loop1: loop2: bool done = radio.write(tx, sizeof(tx)); if(done==false) { retx++; Serial.println("Tx Failed"); if(retx<10) { goto loop2; }else retx=0; } radio.startListening(); print_welcome_message(); }
boolean newBoardAvailable() { if((nBoards < MAX_N_BOARDS) && (nSenActs < MAX_N_SENACT)&&nFreeCH) { radio.stopListening(); radio.setChannel( APPLICATION_CH ); radio.startListening(); if(readPackage(newBoardPacked, 32)) { if(writePackage(newBoardPacked, 32))return true; else { Serial.println("\nError: writng back board"); return false; } } else { //Serial.println("\nError: no New Board"); return false; } } else { Serial.println("Error: no more buffer/channel space"); return false; } }
int main(int argc, char** argv){ radio.begin(); // optionally, increase the delay between retries & # of retries radio.setRetries(0,0); // Dump the configuration of the rf unit for debugging radio.printDetails(); string input = ""; cout << "Choose your node number. #0-6 \n>"; getline(cin,input); int radioNumber = (int)input[0]-48; cout << "input" << input << "\n"; radio.openWritingPipe(pipes[radioNumber]); for (int i = 0; i < 6; i++) { if (i != radioNumber) { cout << i << "\n"; radio.openReadingPipe(i,pipes[i]); } } }
void loadSingleBuffer(boolean wBf){ int bCount = 0; int fails = 0; //if(!playing){return;} while(bCount < buffSize){ if(txSelX(3,0)){ for(int i=0; i<payloadSize; i++){ buffer[wBf][bCount] = tmpArr[i]; bCount++; //if(bCount > buffSize){ Serial.println("BuffSize needs to be a multiple of 32"); noTun(); return;} } //radio.powerUp(); }else{ if(tmpArr[0] == 4 && tmpArr[1] == 3 && tmpArr[2] == 2){ noTun(); retryClose(); Serial.println("ebp"); return; } if(fails >= 300){Serial.println("fail");noTun(); retryClose(); return;} fails++; } radi.powerUp(); } buffEmpty[wBf] = 0; radi.powerUp(); return; }
boolean writePackage(void * package, unsigned char len) { radio.stopListening(); boolean temp = radio.write(package,32); radio.startListening(); return temp; }
void loop(void) { // Clear measurement values memset(values,0,num_channels); // Scan all channels num_reps times int rep_counter = num_reps; while (rep_counter--) { int i = num_channels; while (i--) { // Select this channel radio.setChannel(i); // Listen for a little radio.startListening(); delayMicroseconds(128); radio.stopListening(); // Did we get a carrier? if ( radio.testCarrier() ) ++values[i]; } } // Print out channel measurements, clamped to a single hex digit int i = 0; while ( i < num_channels ) { printf("%x",min(0xf,values[i]&0xf)); ++i; } printf("\n\r"); }
// Setup // void setup(void) { // // Print preamble // printf("\n\rRF24/examples/scanner/\n\r"); // // Setup and configure rf radio // radio.begin(); radio.setAutoAck(false); // Get into standby mode radio.startListening(); radio.stopListening(); // Print out header, high then low digit int i = 0; while ( i < num_channels ) { printf("%x",i>>4); ++i; } printf("\n\r"); i = 0; while ( i < num_channels ) { printf("%x",i&0xf); ++i; } printf("\n\r"); }
bool COM_24g::sendFrame(RF24 _radioCom) { // First, stop listening so we can talk _radioCom.stopListening(); //Opening the writting Pipe _radioCom.openWritingPipe(_writingPipe); delay(20); //put in place the Paypload _payload.type = _dataType; _payload.version = _dataVersion; _payload.data = _data; bool Writestatus = _radioCom.write(&_payload, sizeof(_payload)); if (Writestatus) printf("Communication has been sent successfully. \n"); else printf("Communication has failed.\n\r"); //back in read mode _radioCom.startListening(); }
void drawRF24Pad(){ wclear(rf24Pad); mvwprintw(rf24Pad,1,0,"Address: 0%o\n",mesh.mesh_address); wprintw(rf24Pad,"nodeID: %d\n",mesh.getNodeID()); wprintw(rf24Pad,"En Mesh: %s\n", gw.meshEnabled() ? "True" : "False"); int dr = radio.getDataRate(); wprintw(rf24Pad,"Data-Rate: %s\n", dr == 0 ? "1MBPS" : dr == 1 ? "2MBPS" : dr == 2 ? "250KBPS" : "ERROR" ); int pa = radio.getPALevel(); wprintw(rf24Pad,"PA Level: %s\n", pa == 0 ? "MIN" : pa == 1 ? "LOW" : pa == 2 ? "HIGH" : pa == 3 ? "MAX" : "ERROR" ); wprintw(rf24Pad,"IF Type: %s\n", gw.config_TUN == 1 ? "TUN" : "TAP" ); wprintw(rf24Pad,"IF Drops: %u\n", gw.ifDropped() ); #if defined (ENABLE_NETWORK_STATS) uint32_t ok,fail; network.failures(&fail,&ok); wprintw(rf24Pad,"TX Packets: %u\n", ok ); wprintw(rf24Pad,"TX Drops: %u\n", fail ); #endif if(padSelection == 1){ wattron(rf24Pad,COLOR_PAIR(1)); mvwhline(rf24Pad,rf24Scroll,0,ACS_HLINE, maxY); wattroff(rf24Pad,COLOR_PAIR(1)); mvwprintw(rf24Pad,rf24Scroll,3," RF24Network Info: "); }else{ wattroff(rf24Pad,COLOR_PAIR(1)); mvwhline(rf24Pad,rf24Scroll,0,ACS_HLINE, maxY); mvwprintw(rf24Pad,rf24Scroll,3," RF24Network Info: "); } }
void setup(void){ //Prepare the radio module printf("\nPreparing NRF24L01 interface\n"); radio.begin(); radio.setRetries( 15, 15); radio.setChannel(120); radio.enableAckPayload(); //radio.disableCRC(); radio.setAutoAck(true); radio.openWritingPipe(pipes[0]); radio.openReadingPipe(2,pipes[1]); radio.openReadingPipe(3,pipes[2]); radio.openReadingPipe(1,pipes[0]); radio.printDetails(); printf("\nPreparing MySQL interface.\n"); mysql_connect(); if ((mysql1 != NULL)) { sprintf(SQLstring,"CREATE TABLE IF NOT EXISTS CC_SENSOR_DYN (timestamp DATETIME, id INTEGER, temperature FLOAT, value INTEGER);"); if (!mysql_query(mysql1, SQLstring)) { printf("SQL CC_SENSOR_DYN Table is Ok: %s\n",SQLstring); } else { printf("SQL CC_SENSOR_DYN NOk: %s\n",SQLstring); printf("%s\n", mysql_error(mysql1)); } sprintf(SQLstring,"CREATE TABLE IF NOT EXISTS CC_SENSOR_HIST (timestamp DATETIME, id INTEGER, hist_type VARCHAR(1), hist_period INTEGER, value FLOAT);"); if (!mysql_query(mysql1, SQLstring)) { printf("SQL CC_SENSOR_HIST Table is Ok: %s\n",SQLstring); } else { printf("SQL CC_SENSOR_HIST NOk: %s\n",SQLstring); printf("%s\n", mysql_error(mysql1)); } } radio.startListening(); printf("\nNow Listening...\n"); }
boolean sendRadioCommand(const byte cmd_buffer[]) { if( !radio_hw_available ) { debugPrint("Radio is NOT available"); return false; } int counter = 0; //byte cmd_buffer[] = { 0xFF, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00}; radio.stopListening(); debugPrint("Now sending payload: ",counter); boolean radio_write_ok = false; while( !radio_write_ok && counter < MAX_RADIO_RETRIES ) { radio_write_ok = radio.write(cmd_buffer,8); if( !radio_write_ok ) debugPrint("Retry send: ", counter++); } debugPrint("Payload sent. ",counter); radio.startListening(); return radio_write_ok; }
void setup(void) { TRI_LOG(sizeof(long)); TRI_LOG(sizeof(int)); // Refer to RF24.h or nRF24L01 DS for settings TRI_LOG_STR("radio.begin()"); radio.begin(); TRI_LOG_STR("CONFIGURE_RADIO(radio)"); CONFIGURE_RADIO(radio); // Open 6 pipes for readings ( 5 plus pipe0, also can be used for reading ) radio.openWritingPipe(WRITING_PIPE); radio.openReadingPipe(1, READING_PIPE); radio.startListening(); // // Dump the configuration of the rf unit for debugging // radio.printDetails(); memset(&EMPTY_MESSAGE, 0, sizeof(ArPiMessage)); }
void sendPacket(Packet packet) { radio.stopListening(); radio.openWritingPipe(base_pipe+packet.nodeId); //open pipe unique to the node radio.setAutoAck(0, false); radio.write( &packet, sizeof(Packet) ); radio.startListening(); }
void pcmRF::broadcast(byte device){ noInterrupts(); if(device == 255){ radi.openWritingPipe(addresses[1]); }else{ radi.openWritingPipe(addresses[device+2]); } interrupts(); }
/** fungsi untuk mengirim paket via radio @param paket* alamat ke paket @return ok bernilai true jika pengiriman berhasil, false jika sebaliknya */ bool kirim_paket(paket* paket_dikirim) { uint8_t yang_dikirim[PANJANG_PAKET]; toarray(paket_dikirim, yang_dikirim); printf("ngirim paket gan "); cetakpaket(paket_dikirim); radio.stopListening(); bool ok = radio.write(yang_dikirim, PANJANG_PAKET); radio.startListening(); return ok; }
void loop() { unsigned long time = micros(); unsigned char pipeNo; while(radio.available(&pipeNo)){ radio.read(dmxData, 3); printf("%d %d %d \r\n", dmxData[0], dmxData[1], dmxData[2]); digitalWrite(LED, !digitalRead(LED)); analogWrite(OUT, dmxData[2]); } }
void setup(void) { //maxa = EEPROM.read(CONFIG_START); //EEPROM.write(CONFIG_START, maxa); lcd.begin (20,4); delay(10); lcd.setBacklightPin(BACKLIGHT,POSITIVE); lcd.setBacklight(HIGH); lcd.clear(); delay(10); lcd.home (); Serial.begin(57600); printf_begin(); radio.begin(); radio.setPALevel(RF24_PA_MAX); //RF24_PA_MIN = 0, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX, RF24_PA_ERROR radio.setDataRate(RF24_250KBPS); //RF24_1MBPS = 0, RF24_2MBPS, RF24_250KBPS //radio.setAutoAck(1); radio.setRetries(15,15); radio.enableDynamicPayloads(); radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1, pipes[0]); radio.startListening(); radio.printDetails(); }
void mapFreeCH() { radio.setAutoAck(false); radio.startListening(); radio.stopListening(); for( int i = 30; i< 127; i++) { radio.setChannel(i); radio.startListening(); delay(25); radio.stopListening(); if ( !radio.testCarrier() ) { freeCH[nFreeCH++] = i; } } radio.setAutoAck(true); radio.startListening(); //test printing for (int i =0; i<nFreeCH; i++) { //Serial.println(freeCH[i]); } //Serial.println(""); //Serial.print(freeCH[nextFreeCH]); //Serial.println(""); }
/******************************************************************************** Main ********************************************************************************/ int main(void) { // initialize code usart_init(); // enable interrupts //sei(); _delay_ms(2000); printf("Start NRF24L01P test..."); radio.begin(); radio.setRetries(15,15); radio.setPayloadSize(8); radio.setPALevel(RF24_PA_MAX); radio.setChannel(120); radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); radio.startListening(); radio.printDetails(); loop(); // main loop while (true) { _delay_ms(1000); printf("Elapsed: %u \n", TCNT1); } }
void pcmRF::play(char* filename, byte device){ stop(); rfPlaying = 1; if(device == 255){ radi.openWritingPipe(addresses[1]); }else{ radi.openWritingPipe(addresses[device+2]); } #if !defined(SDFAT) if(!txFile){ txFile = SD.open(filename);} if(txFile){ txFile.seek(24); //skip the header info #else if(!txFile.isOpen()){ txFile.open(filename);} if(txFile.isOpen()){ txFile.seekSet(24); //skip the header info #endif unsigned int SAMPLE_RATE = txFile.read(); SAMPLE_RATE |= txFile.read() << 8; #if !defined(SDFAT) txFile.seek(44); #else txFile.seekSet(44); #endif unsigned int res = (10 * (1600000/SAMPLE_RATE)) * 32; noInterrupts(); ICR1 = res; TCCR1A = _BV(WGM11); TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); TIMSK1 = ( _BV(OCIE1A) ); interrupts(); }else{ #if defined (debug) Serial.println("failed to open music file"); #endif } } ISR(TIMER1_COMPA_vect){ radi.writeFast(&buff,32); txFile.read((byte*)buff,32); if(txFile.available() < 32){ radi.txStandBy(); stop(); } }
void loop(void) { char receivePayload[PAYLOAD_SIZE]; while ( radio.available() ) { uint8_t len = PAYLOAD_SIZE; radio.read( receivePayload, len ); //structure of data: 2bytes (int)-humidity | 2bytes (int)-thermistor | 2bytes (int) - mV int hum = 0; hum = receivePayload[1] << 8; hum = hum + receivePayload[0]; int thermistor = 0; thermistor = receivePayload[3] << 8; thermistor = thermistor + receivePayload[2]; int mV = 0; mV = receivePayload[5] << 8; mV = mV + receivePayload[4]; //convert the reading to mV mV = 1126400 / mV; //1100mV*1024=1126400 //calculate temperature double temp = calcTemp(mV, thermistor); time_t t; t = time ( NULL ); //write data to file ofstream file ("data.txt", ios::out | ios::app); if(file.is_open()){ file << temp << ", " << t << "\n"; file.close(); } //print data printf("Payload: size=%i bytes",len); printf("\nHumidity: %i", hum); printf("\nBattery status (mV): %i", mV); printf("\nTemp (C): %f", temp); printf("\nTime: %ld", t); printf("\n\n"); //start the update script FILE *stream = popen("python updater.py", "r"); pclose(stream); } sleep(1); }
void setNodeId(uint8_t id) { // Set the node ID addresses[0][0] = clientConfig.nodeId; // Stop listening radio.stopListening(); // Open new pipe with new ID radio.openReadingPipe(1, addresses[0]); // Strart listening for commands radio.startListening(); }
void loop() { radio.stopListening(); uint8_t data[] = {111, 101}; bool ok = radio.write(data, 2); if (ok) printf("ok...\n\r"); else printf("failed.\n\r"); }
void RF24Loop(void) { if ( radio.available() ) { Packet packet; radio.read( &packet, sizeof(Packet) ); _processPacket(packet); } }
void setup() { Serial.begin(9600); //delay(1000); radio.begin(); print_welcome_message(); radio.openReadingPipe(1,pipe[0]);//For Receiving Operation radio.openWritingPipe(pipe[1]);//For Transmitting Operation radio.startListening(); }
void setup() { Serial.begin(115200); printf_begin(); Serial.println(F("\n\n** NeoPixelWirelessClient ** \n\n")); Serial.println(F("Reading client configuration....")); if( !readClientConfiguration( (client_configuration_t *)&clientConfig) ) { Serial.println(F("** Error reading client configuration\n")); clientConfig.version = CLIENT_CONFIG_V10; clientConfig.nodeId = 0x01; if( !writeClientConfiguration((client_configuration_t *)&clientConfig) ) { Serial.println(F("** Error writing client configuration\n")); } else { Serial.println(F("Successfully wrote client configuration\n")); } } else { Serial.println(F("Successfully Read Configuration:\n")); } dumpClientConfiguration((client_configuration_t *)&clientConfig); // Setup and configure radio radio.begin(); radio.enableAckPayload(); // enable payload ack radio.enableDynamicPayloads(); // Ack payloads are dynamic payloads setNodeId(clientConfig.nodeId); // radio.openWritingPipe(addresses[1]); // radio.openReadingPipe(1, addresses[0]); // radio.startListening(); // we're the client, so start listening radio.writeAckPayload(1, &message_count, sizeof(message_count)); ++message_count; radio.printDetails(); // Dump the configuration of the rf unit for debugging delay(50); attachInterrupt(0, check_radio, LOW); // Attach interrupt handler to interrupt #0 (using pin 2) on BOTH the sender and receiver if (controller.initialize(50, 2) == false) { } else { controller.fill(CRGB::Black, true); } }
void COM_24g::listeningPipe(RF24 _radioCom) //Listen all available pipes { int i; for (i=1;i<5;i++) { if (_readingPipe[i] != NULL) { _radioCom.openReadingPipe(i,_readingPipe[i]); } } _radioCom.startListening(); _radioCom.powerUp(); }
int main(int argc, char** argv){ // bool role_ping_out = true, role_pong_back = false; // bool role = role_pong_back; printf("RF24/examples/GettingStarted/\n"); // Setup and configure rf radio radio.begin(); radio.setChannel(2); radio.setDataRate(RF24_2MBPS); radio.setPayloadSize(8); // optionally, increase the delay between retries & # of retries // radio.setRetries(15,15); // Dump the configuration of the rf unit for debugging radio.printDetails(); /***********************************/ radio.startListening(); // forever loop while (1) { // if there is data ready if ( radio.available() ) { // Dump the payloads until we've gotten everything unsigned long got_time; // Fetch the payload, and see if this was the last one. while(radio.available()){ radio.read( &got_time, sizeof(unsigned long) ); } // radio.stopListening(); // radio.write( &got_time, sizeof(unsigned long) ); // Now, resume listening so we catch the next packets. // radio.startListening(); // Spew it printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time); } delay(925); //Delay after payload responded to, minimize RPi CPU time printf("."); fflush(stdout); // radio.printDetails(); } // forever loop return 0; }
int main(int argc, char** argv) { printf("RF24 example starting.") /** Set up the radio **/ radio.begin(); radio.setRetries(15, 15); radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1, pipes[1]); radio.startListening(); /** Loop forever, writing and then listening for response **/ while (1) { /** Send out the current time **/ radio.stopListening(); unsigned long time = millis(); bool ok = radio.write(&time, sizeof(unsigned long)); if (!ok) printf("Failed to send for some reason.\n"); radio.startListening(); /** Start waiting around for the response **/ unsigned long started_waiting_at = millis(); bool timeout = false; while( !radio.available() && !timeout ) { if (millis() - started_waiting_at > 200) timeout = true; } /** Describe the results **/ if (timeout) { printf("Failed. Response timed out.\n") } else { unsigned long got_time; radio.read(&got_time, sizeof(unsigned long)) printf("Got response %lu, round-trip delay: %lu\n", got_time, millis() - got_time); sleep(1); } }