So im going true this process where I'm getting data from An ENC28J60 device with the Ethercard libraries using the udp listener, and I want then to send that data to an NRF24l01 device using MIRF. The data does get from the network and showed in the serial window no problem, And the sending process from the serial Window to the NRF device and get's to another NRF device and come out of the serial window of the receiving device. So every thing work well in theories, both device work in the same time on one Arduino no problem.
However, I have a small variable conversion problem, Here is the code:
When I connect the computer by using the UDP Processing example, data goes to Arduino, come out no problem, And Arduino does send some stuff true the NRF Device, but Only bogus character, always the same, or space character come out the other end of the NRF. But it always send the right amount of character. If I simply send from the serial window true the NRF, it will work.
In the receiver program, on the other side of the NRF connection, I've remove the (char) int front of the variable buf[1] so it look like this:
Serial.print (buf[1]);
instead of:
Serial.print ((char)buf[1]);
And now only the number "1", instead of the space character, come out of the serial window.
It's not usign the same libraries as the sender, but since it's communicating on the same channel, and considering that the data goes true when I'm not trying to get it true the UDP link, it doesn't really matter.
Are you using the official wifi shield? Cause if you are, you are gonna have lot less trouble then I did, but I won't have a direct code to propose, since i'm using some thing else.
And also, what do you plan to do exactly? a simple repeater?
I got some thing that receive UDP and send TCP for practical reason maybe it can help but it's for ENC28J60 network board so it would need some adaptation.
It use Mirf instead of the NRF24 libraries cause Mirf is compatible at the level of the spi driver with the Ethercard Librairies.
So this is fully bi-directionnal. It listen on the Serial, NRF and the ENC devices and when it receive something from one it send it to the other.
Work super well. NRF use Pin 9 ans 10 and listen to chanel 50, ENC use Pin 8.
have no Wifi shield yet but a NRF24L01+ - Modul.
I want to transfer datas via the Wlan to a PC software - that transfer isnt a problem with Bluetooth, but i want to use the wlan instead.
But i have no experiences with that and reading the different threads and postings let me get more confused
Here my code to connect via BlueTooth (with a SmartPhone and an App) and send and receive data (as bytes).
#include <SoftwareSerial.h>
SoftwareSerial softSerial(8, 7); // RX, TX Setup to use pin 10 and 11 of the Arduino to connect to the bluetooth module
String command = ""; // Stores response of bluetooth device
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
// Set the Arduino's serial port so we can use the Arduino Serial Monitor (top right 'spyglas' in the Arduino software) Then we can type stuff live and send it over bluetooth.
softSerial.begin(9600);
// SoftwareSerial port is the one for sending and receiving over Bluetooth
}
void loop() // the start of the loop
{
// Read device output if available.
while(softSerial.available()) { // While there is more to be read, keep reading.
command += (char)softSerial.read();
delay(2000); // gives it a chance to get all the characters.
}
if(command != ""){ // so if there is something in the string 'command' If command doesn't equal "" (if its not empty!) then print it to the
Serial.println(command); // Arduino's Serial Monitor and what's in 'command' is what has been received over the Bluetooth link.
}
if(command == "A"){
// the first thing that happens upon connect is that BTInterface sends the string 'btinterface' to let the device know its connected.
softSerial.println("A"); // sending 'screen1' will cause BTInterface to show screen1
Serial.println("ToggleButton ON");
delay(1000); // wait a second to give it a chance to get all the characters.
}
if(command == "a"){
softSerial.println("a");
Serial.println("ToggleButton OFF");
}
// this is how easy it is to use, wait for a command like b1 (for button one) etc. then
// act on that command and send something back over the bluetooth link. Here if BTInterface sends 'ping' the Arduino sends back 'pong'
command = ""; // Empty the command string so we can start again.
// Read user input if available. This bit is for debugging, if you write anything into the Arduino Serial Monitor
if (Serial.available()){ // and press Return it will be sent over the Bluetooth link.
softSerial.write(Serial.read()); // send whatever was written over the bluetooth link
}
}// the end of the loop
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// start the server:
server.begin();
// you're connected now, so print out the status:
printWifiStatus();
}
void loop() {
// wait for a new client:
WiFiClient client = server.available();
// when the client sends the first byte, say hello:
if (client) {
if (!alreadyConnected) {
// clead out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}
if (client.available() > 0) {
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);
}
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Try it, tel me if it work and how mutch memory it use. Then post it back with the modification that you made to make it work. From there ill add some stuff to make it talk to the NFR module.