#include "RF24.h" #include "printf.h" #include "CRC8.h" RF24 radio(9, 10); CRC8 crc; // SErial WR // 1141 72607952 uint8_t addrWR[5] = {0x52, 0x79, 0x60, 0x72, 0x01}; uint8_t addrDTU[5] = {0x32, 0x88, 0x81, 0x72, 0x01}; #define PAYLOAD 27 #define KANAL 3 // Kanal 3, 23, 40, 61 oder 75 uint8_t data[32]; uint8_t receive_payload[32]; uint8_t datalen = 0; void dump(char * was, uint8_t * data, int len) { //============================================== Serial.print (was); for (byte i = 0; i < len; i++) { Serial.print(data[i], HEX); Serial.print(' '); } Serial.println(); } void setup(void){ //--------------- byte address[] = {0xCC, 0xCE, 0xCC, 0xCE, 0xCC}; Serial.begin(9600); printf_begin(); radio.begin(); radio.setAutoAck( false); // !!!! muss false sein sonst klappt senden nicht radio.setPALevel(RF24_PA_MAX); radio.setChannel (KANAL); radio.setDataRate (RF24_250KBPS); radio.openWritingPipe(addrWR); radio.openReadingPipe(0, addrWR); // using pipe 0 radio.setPayloadSize(PAYLOAD); radio.openReadingPipe(1, addrDTU); // using pipe 1 //radio.enableDynamicPayloads(); //radio.enableDynamicAck(); //radio.enableAckPayload(); //radio.setCRCLength(1); // Get into standby mode radio.startListening(); radio.stopListening(); radio.printDetails(); crc.setPolynome(0x01); crc.setStartXOR(0); crc.setEndXOR(0); } boolean send() { radio.stopListening(); //radio.openWritingPipe(addrWR); delay(10); return radio.write(data, PAYLOAD); } uint8_t receive () { uint8_t pipe; //radio.openReadingPipe(0, addrWR); radio.startListening(); unsigned long start = millis(); while (!radio.available() && millis() < start +2000) delay(10); //delay(500); if (radio.available(&pipe)) { // is there a payload? get the pipe number that recieved it uint8_t bytes = radio.getPayloadSize(); // get the size of the payload radio.read (receive_payload, bytes); // fetch payload from FIFO Serial.print(F("gelesen ")); Serial.print(bytes); // print the size of the payload Serial.print(F(" bytes auf Pipe ")); Serial.print(pipe); // print the pipe number return bytes; } return 0; } void tele7 () { //============= memset (data, 0, 32); data[0] = 0x07; data[10] = 0x07; datalen = 11; } void teleInit2() { //============== memset (data, 0, 32); uint8_t i = 0; data[i++] = 0x07; data[i++] = addrWR[3]; data[i++] = addrWR[2]; data[i++] = addrWR[1]; data[i++] = addrWR[0]; data[i++] = addrDTU[3]; data[i++] = addrDTU[2]; data[i++] = addrDTU[1]; data[i++] = addrDTU[0]; /* data[i++] = addrDTU[3]; data[i++] = addrDTU[2]; data[i++] = addrDTU[1]; data[i++] = addrDTU[0];*/ data[i++] = 0x00; crc.restart(); crc.add (data, 10); data[i++] = crc.getCRC(); //0x07; datalen = i; } void teleGetData() { //---------------- memset (data, 0, 32); uint8_t i = 0; data[i++] = 0x15; data[i++] = addrWR[3]; data[i++] = addrWR[2]; data[i++] = addrWR[1]; data[i++] = addrWR[0]; data[i++] = addrDTU[3]; data[i++] = addrDTU[2]; data[i++] = addrDTU[1]; data[i++] = addrDTU[0]; data[i++] = 0x80; data[i++] = 0x0B; data[i++] = 0x00; //time_t t = now(); data[i++] = 0x62; data[i++] = 0x09; data[i++] = 0x04; data[i++] = 0x9b; i +=8; // 8 Nullen data[i++] = 0x02; // ? data[i++] = 0x29; // ? crc.restart(); crc.add (data, i); data[i++] = crc.getCRC(); //0x07; datalen = i; } boolean replied = false; uint8_t step = 3; void loop() { //========= if (replied) return; if (step == 1) { Serial.println("Init 1"); tele7 (); } else if (step == 2) { Serial.println("Init 2"); teleInit2 (); } else if (step == 3) { Serial.println("Tele 15, getData"); teleGetData(); } else ; dump ("send: ", data, datalen); if (!send()) Serial.println("Senden fehlg."); { memset (receive_payload, 0, sizeof(receive_payload)); datalen = receive (); if (datalen) dump ("empf.:", receive_payload, datalen); else Serial.println ("keine Antwort vom WR!"); } delay(1000); }