We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello friends, I have a simple example that runs perfectly with the NET library. I would like to do exactly the same process but using the OCSP5 library. I have tried in many ways without success. If anyone can help me, thank you.
import processing.net.*;
Client c;
void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "192.168.1.2", 8080); // Connect to server on port 8080
}
void draw() {
c.write("rele1");
delay(2000);
}
Answers
Can you give an example of what you tried with the OscP5 library that didn't work? It's easier to correct mistakes than giving a complete solution.
Bear in mind that an OSC message requires an address pattern in addition to a target IP address and port.
I have a hardware that changes the state of a relay when it receives the string "rele1". Using the java mode processing and this sketch I put here works fine but I could not use any examples from the ocsp5 library to do what I need. I changed the ip and port values in the examples. It does not make a mistake but it's not right, I can not change the state of the relay by sending this string. About what I did in the ocsp5 examples, I just changed ip and port.
That won't work. You need to know the address pattern. I suspect "rele1" is actually the address pattern and you need to send a blank message. So try to modify an OscP5 example so it sends an empty message with "rele1" or "/rele1" as its address pattern. This might already work (it's a slightly modified OscP5 example sketch):
If "rele1" is not the address pattern, the specification of your device should specify what it is then, since an OSC message always requires this.
The default communication is TCP, I have to create a socket between the program and the hardware. This example I have tested and not obitive success. I tried the example ocsp5tcop and a message appears in my console that the socket was successfully created but the communication does not happen. What I find strange is that when I give the command:
Println (myMessage);
What I get in response is:
I do not know why this null: 0 | pops up. What can it be? Thank you very much in advance.
I think the Null and 0 refer to the IP address and port, respectively. That they're null/0 probably means that the message was not sent properly or something went wrong. Could you share your whole code please? Or at least the relevant part to sending the OSC message.
This code is what I'm using, and below is the output on the console:
__OscP5 0.9.9 infos, comments, questions at http://www.sojamo.de/oscP5
[2017/4/21 19:58:6] PROCESS @ OscP5 stopped.
[2017/4/21 19:58:7] PROCESS @ TcpServer ServerSocket started @ 11000
OscP5 0.9.9 infos, comments, questions at http://www.sojamo.de/oscP5
[2017/4/21 19:58:7] PROCESS @ OscP5 stopped.
[2017/4/21 19:58:8] PROCESS @ TcpClient ### starting new TcpClient 192.168.1.2:8080_
_
Where did you put the println(myMessage);? What happens when you click with the mouse in the sketch?
Do you have a specification document for the device?
It was a mess of mine, that's not why I give the println command. In this example, if I click the mouse nothing happens. If I press any key it returns me "0".
This is the sketch that returns me "null: 0 | rele1" when I just assign the value "rele1" to the variable myOscMessage
I think that just means the OscP5.flush() method does not change the myOscMessage variable.
When I tried your TCP sketch this is my output:
then when I hit a key in the window I get a "0". This tells me there are no clients. I have no experience with this method of sending OSC.
Trying to find something obvious we missed:
Does that mean the code you posted in your first post manages to activate the relay?
The first sketch I put in works fine. I'm migrating from library because ocsp5 has support for android mode
Why are you using port 8080? Is this part of the instruction from your device?
What you need to do first is run two sketches. One to be the client and one to be the server. You will use a different port, and avoid those ones with defined functionalities. For example, 12345 is a common one to try. You need to become familiar with how oscP5 works. It is not difficult to get it running and to send data between sketches. The sketches could even be running in different computers. However, they both need to be under the same network. One needs to be a server and the second needs to be a client. The server must be running first, as you might already know.
To clarify, you are using your NET library at all. You are using Processing to communicate to your Android device? I have tested oscP5 in android and it works fine. I will suggest using UDP to start. UDP is just the standard protocol used by oscP5. Then you can switch to TCP/IP.
The examples of this page are perfect for your case: http://www.sojamo.de/libraries/oscP5/#examples
Kf
Ohhhh. #-o That means OSC won't work. An OSC message follows a strict structure. It starts with a string identifying itself as an OSC command, then there is a type tag string and the command string and probably some other information too. It's not just the command string but a whole lot of fluff too. The device does not implement the OSC protocol and does not know what to do with the information it receives. You can't use the OSC library for your purpose and your original question is wrong, it should actually be "how can one send TCP messages in android mode".
Yes, my device is configured for an 8080 port, I can change it though I do not think so.
On this, I saw a video note 10 that explains very well about this process:
In fact my intention is to communicate android with ESP8266. All the communications I make between antre processing and ESP I use UDP. But this hardware that I have specifically it is not my product and already has an application of its own. What do I want and make another computer program from scratch. But in the future I will only use UDP.
I understand. But when I search TCP android what comes next is this library. If it does not work for now, I'll go look for some others. Do you know any?
To clarify, ESP8266 is an external hardware and you want to use Processing to build an application that allows you to connect to this device. The device is a wifi module so I understand. You can use the ketai library. It has a WiFi example that you could use for your application.
For oscP5, it works in android mode and it will work out of the box if it talks to another application running osc. If you want to run oscP5 on Android on one side and the processing'e net library in a computer on the other side, android will be able to deliver messages to the P3 net program. However, sending data to the android won't work. The reason is that oscP5 expects certain format when receiving data. I believe if you build this structure in your computer side right before you send it, the oscP5 on the Android side should be able to read it. I haven't tried myself.... it is just an idea.
Kf
Sorry for the delay in answering, I was testing. I gave up trying to use the ocsp5 library to trigger that hardware I had here. I will not need it in the future. Using esp8266 + ocsp + UDP worked very well. As for the Ketai library seems interesting but I have not tested it yet. Thank you, from the bottom of my heart, for personal help.