this is part of an example that came with the enc28j60 library. My problem now is, I want to write the data to control the state of an output.
The data I send via udp is "HIGH" and in the serial monitor it writes it as it´s supposed to. But if I want to use digitalWtite(outputPin, data) I get an error message that "data" was not declared in this scope.
Somebody knows what I am doing wrong? Do I need to write the data in a Buffer? If yes how can I do that?
I´ve attached the sketch I wrote so far as well for better understanding.
I am trying to control outputs from the Arduino via udp and only udp. My problem is probably quite trivial but I spent the whole night already finding a solution and just don´t get there.
I started out with a example sketch from the ethernet Master library. Now what I would like to do is if I receive a message for example on port 7050 I would like to change the actual state of an output (off >> on >> off>>on and so on). And if I send a message on port 7051 change the state of another output.
Does anybody have an idea how I can realize that? I´ve done it already with an ethernetshield W5100, but I just can´t get it running with the enc28j60 chip.
I am happy for any ideas. As I said the sketch is attached.
No it just compiled but if I wanted to read out the udp message I don´t get anything so I need to find a different solution. But the link you gave me is great I already studied half of the tutorial.
You are right it is not working. The problem is that it doesn´t write the message i sent. Do you know how I can get the data for using it in the loop fuction? Or better could you tell me cause you know it for sure.
Sorry I forgot? But I spent the whole night reading web pages and trying stuff I am not at 100% anymore. I attached the sketch but it´s not finished yet I wanted too first fix the communication.
And please don´t blame me if my code is sh... but as I said I am trying too llearn. :.
//callback that prints received packets to the serial port
void udpSerialPrint(word port, byte ip[], const char *data, word len) {
IPAddress src(ip[0], ip[1], ip[2], ip[3]);
Serial.println(src);
Serial.println(port);
Serial.println(data);
}
The callback can do more than print the data received.
Get rid
of all the stupid white space
in your code.
Describe what you are sending, from where, and what the Arduino claims to be receiving.
Yeah I know that port stuff is a left over from trying things out. And it seemed too me that it would be easier if I split it up a little bit, but I got the point in your message this is something I am going to change in future codes.
Actually I was planning to send something like "Licht1", "Licht2" ........ but I can send any textmessage I want or need. And I send from a static IP Address with the UDP ports 7050 ........,
I send the same message for on and off and it is sent only once for every action.
Thank´s for spending your time for my problem and
Hi Paul
that is what the Arduino is going too receive. I will not send with the Arduino only receiving. I am sorry it was not good communicated from me that´s because o my english is getting worse as I don´t speek it that often anymore,
I describe it a little more detailed.
The Arduio is only some kind of a output modul for a PLC in my home automation system. The PLC acts as server and has a static IP Address. I don´t even need acknowledgement since this is done also by the PLC via hardware response. So all the Arduino needs to do is if it receives a UDP message on port 7050 change the state of output1, incoming message on port 7051 change the state of output2 and so on
Why particularly do you want to use port numbers to tell you which output to use? Usually, arduino ethernet libraries have few sockets available (four?) so this method isn't very scalable - it would seem more sensible to use the message content. Are you restricted by the capabilities of the PLC?
The problem is the PLC. If you use a UDP port in one function you can not use it in another one anymore. The only thing I can tell the PLC is the starting address, the destination and the message being send in case of being triggered.
The library for my enc28j60 I have from the manufactors homepage.
The frustrating thing is that I have a sketch that does exactly what I want but this is for the W5100. I would rather use the enc28j60 cause of its integrated POE modul.