Go Down

Topic: Output control via UDP (Read 3629 times) previous topic - next topic

Stuff23

Hello all

I have a problem writing a received udp packet to an output. Here is a part of my sketch:

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);
 
}

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.

Thank´s in advance already and greetings

Stefan

Qdeathstar

not experienced with this but here is my guess...

http://www.cplusplus.com/doc/tutorial/pointers/

The problem might be that const char *data is a pointer to a character type variable,

according to that link, you might need to do something like this:

Code: [Select]

//declare global variable

char pinState;


// in setup()

void udpSerialPrint(word port, byte ip[], const char *data, word len) {
  IPAddress src(ip[0], ip[1], ip[2], ip[3]);
  data = &pinState;
  Serial.println(src);
  Serial.println(port);
  Serial.println(data); 
}


// in loop
digitalWrite(outputPin, pinState);




but, I'm only basing my advice on that link....


A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Stuff23

All right I give it a try thank´s a lot

Stuff23

Yes it is compiling now I thank you again for the quick reply and also for the link it may help me in the future with some other problems.

Greetings Stefan

Stuff23

#4
Oct 03, 2014, 11:53 am Last Edit: Oct 03, 2014, 01:40 pm by Stuff23 Reason: 1
Hi guys

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.

Thanks in advance and  greetings

Stefan

Qdeathstar

Out of curiousity, did the advice I gave you yesterday about the pointers work?
A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

Stuff23

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.

Greetings Stefan

PaulS

Quote
Yes it is compiling now

That doesn't mean that it works. Reassigning the pointer data, to point to somewhere else makes no sense.

You need to show where you tried to use data, and what your serial output looks like.
The art of getting good answers lies in asking good questions.

Stuff23

Hi Paul

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.

PaulS

Quote
Or better could you tell me cause you know it for sure.

Without seeing all your code, all anyone can do is guess.
The art of getting good answers lies in asking good questions.

Stuff23

#10
Oct 03, 2014, 10:54 pm Last Edit: Oct 03, 2014, 10:57 pm by Stuff23 Reason: 1
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.  :.

Thank´s and greetings

Stefan

nickgammon

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Stuff23

Sorry that was a mistake! Won´t happen again.

PaulS

Code: [Select]
int port = port;
WTF?

Code: [Select]
//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.
The art of getting good answers lies in asking good questions.

Stuff23

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

Greetings  Stefan

Go Up