Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Arduino.h"
- #include <SPI.h>
- #include <RF24.h>
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <SPI.h>
- byte MAC[] = { 0xDE, 0x12, 0x44, 0xAF, 0xBE, 0x56 };
- IPAddress IP(192, 168, 2, 100);
- unsigned int localPort = 5000;
- char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
- String dataReq;
- int packetSize;
- EthernetUDP UDP;
- RF24 radio(7, 8);
- byte addresses[][6] = { "1Node", "2Node" };
- char receivedData[32];
- char data1[32];
- void setup() {
- Serial.begin(9600);
- Ethernet.begin(MAC, IP);
- delay(1500);
- UDP.begin(localPort);
- Serial.println(Ethernet.localIP());
- Serial.println("THIS IS THE TRANSMITTER CODE - YOU NEED THE OTHER ARDIUNO TO SEND BACK A RESPONSE");
- radio.begin();
- radio.setPALevel(RF24_PA_MIN);
- radio.setDataRate(RF24_2MBPS);
- radio.setChannel(124);
- radio.openWritingPipe(addresses[1]);
- radio.openReadingPipe(1, addresses[0]);
- }
- void loop() {
- packetSize = UDP.parsePacket();
- if (packetSize > 0) {
- Serial.println("YAAAAAA BITCH");
- }
- radio.stopListening();
- String neki = "RLY0212Node";
- neki.toCharArray(data1, 32);
- if (!radio.write(&data1, sizeof(data1))) {
- // Serial.println("No acknowledgement of transmission - receiving radio device connected?");
- // Serial.println("bruh");
- }
- // Now listen for a response
- radio.startListening();
- // But we won't listen for long, 200 milliseconds is enough
- unsigned long started_waiting_at = millis();
- // Loop here until we get indication that some data is ready for us to read (or we time out)
- while (!radio.available()) {
- if (millis() - started_waiting_at > 200) {
- return;
- }
- }
- // Now read the data that is waiting for us in the nRF24L01's buffer
- unsigned char dataRx;
- radio.read(&receivedData, sizeof(receivedData));
- // Show user what we sent and what we got back
- Serial.print("Sent: ");
- Serial.print(neki);
- Serial.print(", received: ");
- Serial.println(receivedData);
- // Try again 1s later
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement