Advertisement
rozman50

ArduinoMastr - send/receive wifi works, ethernet conf.begin

May 17th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <SPI.h>
  3. #include <RF24.h>
  4. #include <Ethernet.h>
  5. #include <EthernetUdp.h>
  6. #include <SPI.h>
  7.  
  8.  
  9. byte MAC[] = { 0xDE, 0x12, 0x44, 0xAF, 0xBE, 0x56 };
  10. IPAddress IP(192, 168, 2, 100);
  11. unsigned int localPort = 5000;
  12.  
  13. char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
  14. String dataReq;
  15. int packetSize;
  16.  
  17. EthernetUDP UDP;
  18.  
  19. RF24 radio(7, 8);
  20. byte addresses[][6] = { "1Node", "2Node" };
  21.  
  22. char receivedData[32];
  23. char data1[32];
  24.  
  25. void setup() {
  26. Serial.begin(9600);
  27.  
  28. Ethernet.begin(MAC, IP);
  29. delay(1500);
  30. UDP.begin(localPort);
  31. Serial.println(Ethernet.localIP());
  32.  
  33. Serial.println("THIS IS THE TRANSMITTER CODE - YOU NEED THE OTHER ARDIUNO TO SEND BACK A RESPONSE");
  34.  
  35. radio.begin();
  36. radio.setPALevel(RF24_PA_MIN);
  37. radio.setDataRate(RF24_2MBPS);
  38. radio.setChannel(124);
  39.  
  40. radio.openWritingPipe(addresses[1]);
  41. radio.openReadingPipe(1, addresses[0]);
  42.  
  43. }
  44.  
  45. void loop() {
  46.  
  47. packetSize = UDP.parsePacket();
  48. if (packetSize > 0) {
  49. Serial.println("YAAAAAA BITCH");
  50. }
  51.  
  52.  
  53.  
  54. radio.stopListening();
  55.  
  56. String neki = "RLY0212Node";
  57.  
  58. neki.toCharArray(data1, 32);
  59.  
  60. if (!radio.write(&data1, sizeof(data1))) {
  61. // Serial.println("No acknowledgement of transmission - receiving radio device connected?");
  62. // Serial.println("bruh");
  63. }
  64.  
  65. // Now listen for a response
  66. radio.startListening();
  67.  
  68.  
  69.  
  70. // But we won't listen for long, 200 milliseconds is enough
  71. unsigned long started_waiting_at = millis();
  72.  
  73. // Loop here until we get indication that some data is ready for us to read (or we time out)
  74.  
  75.  
  76. while (!radio.available()) {
  77. if (millis() - started_waiting_at > 200) {
  78. return;
  79. }
  80. }
  81. // Now read the data that is waiting for us in the nRF24L01's buffer
  82. unsigned char dataRx;
  83. radio.read(&receivedData, sizeof(receivedData));
  84.  
  85. // Show user what we sent and what we got back
  86. Serial.print("Sent: ");
  87. Serial.print(neki);
  88. Serial.print(", received: ");
  89. Serial.println(receivedData);
  90.  
  91. // Try again 1s later
  92. delay(500);
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement