oscP5:TcpClient IOException while trying to create a new socket

Good morning.
It is the first time that I try to write a topic and therefore I apologize if the form is not entirely correct
I write as I am trying to make my tablet (HUAWEI MEDIA PAD T5) communicate with an arduino MKR 1010 via local network.

Unfortunately I cannot use the standard “processing.net. *” Library, as it is not supported by Processing in the Android version.
To overcome this problem, by reading on the internet I am trying to establish communication through the OscP5 library.
The architecture I thought of is to create a processing client that connects to a server on the Arduino.

So I wrote the following code that works perfectly in Processing -Java mode:

mport oscP5.*;
import netP5.*;

OscP5 oscP5tcpClient;
NetAddress myServerAddress;

void setup() { 
  oscP5tcpClient = new OscP5(this, "192.168.1.54", 2300, OscP5.TCP);
}

void draw() {
  background(0);
}

void mousePressed() {
  oscP5tcpClient.send("#123456789!", new Object[] {new Integer(1)});
}

void keyPressed() {
}

void oscEvent(OscMessage theMessage) {
  System.out.println("### got a message " + theMessage);
  if (theMessage.checkAddrPattern("/test")) {
    OscMessage m = new OscMessage("/response");
    m.add("server response: got it");
  }
}

Unfortunately when I try to load it on the tablet I get the following error:

BUILD SUCCESSFUL in 37s
28 actionable tasks: 28 executed
OscP5 0.9.9 infos, comments, questions at http://www.sojamo.de/oscP5

[2020/3/1 14:20:21] PROCESS @ OscP5 stopped.

[2020/3/1 14:20:21] ERROR @ TcpClient IOException while trying to create a new socket.

I think I understand there is a problem in opening the soket, but I don’t understand how to solve it.
I am grateful to anyone who can help me solve the problem.
Thank you

1 Like

I am interested in this as well.
I never could OcsP5 android examples get working…
Even if you use only oscP5tcpClient = new OscP5(this, "adress etc
it will crash the sketch.
Here is a discussion.

1 Like

Thank you.
Problem solved.
I have enabled “CHANGE WIFI MULTICAST STATE” on processing and now it works

1 Like

Now I am jealous.
I’ve tried the whole set of possible permissions, and the Ip adress as well as the broadcast adress, but without success.
Does the oscP5message example which sends the message back to the phone work on your phone?

1 Like

I have given all the permits and the above code and code functions
To be honest arduino comes the string I sent with a head made up of the following ascii code: 0,0,0,28 and a tail made up of the following ascii code: 0,0,0,0,44,105,0,0 , 0,0,0,1.
Cut off head and tail and you’re done.

Now I have the reverse problem: sending a string from arduino to processing.
Since I understand that oscP5 is one-way, I have found to encapsulate the message in the head and tail above and send it to processing.
But the code does not detect a message.

this is the code with which I send it

#ifdef MKRWIFI1010
      //header
     // Serial.println ("OUT");
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(28));
     // Serial.print(char(28));
     // Serial.println ("OUT");

      for (y = 0; y < 11; y++)
      {
        if (y == 0)
        {
          WiFiDrv::analogWrite(27, 255); //ACCENDO IL LED BLU
        }
        client.print(messageOut[y]);
        if (y == 10)
        {
          WiFiDrv::analogWrite(27, 0); //SPENGO IL LED BLU
          lettoMessaggio = false;
        }
      }
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(44));
      client.print(char(105));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(1));

#endif

I also tried to create a tcp server with arduino and send the string, but always without result.

:disappointed_relieved: :disappointed_relieved: :disappointed_relieved:

In practice I can only communicate from Android to Arduino and not the other way round.
Can anyone help me?
Thanks 1000

Where can I find a link of the exact same OscP5 zip folder that you are using?

I install the OscP5 library directly from Processing.
The version is the 0.0.9.
The link is:
http://www.sojamo.de/libraries/oscp5/

Sorry… version 0.9.9 e not 0.0.9 :crazy_face:

That’s the one I’m using.
The Ketai lib examples also contain Wifi sketches, but they also use the OscP5 lib.
The sketch discovers the adresses of all devices, but as soon I connect, and declare
OscMessage m = new NetAddress(clientip, 12000);
I get the error

java.lang.NoClassDefFoundError: Failed resolution of: LoscP5/OscMessage;

I’m using Lollipop and your’s seems to be Nougat. Maybe that’s the difference

I use oreo.

Maybe it’s best to write the code directly in Java, but unfortunately I’m not very Java expert

@RoboTonzo
Tht UDP library does seemingly work with processing as well.
https://forum.processing.org/one/topic/library-incompatible-with-this-version-of-processing.html
Here’s a arduino tutorial
https://www.arduino.cc/en/Tutorial/UDPSendReceiveString

@RoboTonzo
I am working with the APDE apk.
The error mentioned above that the builder can not reach the classes, is because this app requeres a full structured library with a dex.jar, So I build this new jar and now the the devices do connect. I will post another topic with a link to download this modified lib for APDE users.
As for sending to processing to Arduino, maybe you’ll find the “Serial WiFi Termina” apk ( als on Play Store) of interest, to verify what exactly is send from the Arduino, specially the needed address pattern and typetag.
I hope you keep us informed on your progress.

Thanks for your help
I’ll post the piece of Arduino code that doesn’t work where I try to send a message to android.
For the moment I am still until I can solve the problem.

#ifdef MKRWIFI1010
      //header
     // Serial.println ("OUT");
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(28));
     // Serial.print(char(28));
     // Serial.println ("OUT");

      for (y = 0; y < 11; y++)
      {
        if (y == 0)
        {
          WiFiDrv::analogWrite(27, 255); //ACCENDO IL LED BLU
        }
        client.print(messageOut[y]);
        if (y == 10)
        {
          WiFiDrv::analogWrite(27, 0); //SPENGO IL LED BLU
          lettoMessaggio = false;
        }
      }
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(44));
      client.print(char(105));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(0));
      client.print(char(1));

#endif

Instead the following is the Processing code:

import oscP5.*;
import netP5.*;

OscP5 oscP5tcpClient;
NetAddress myServerAddress;

void setup() {
  oscP5tcpClient = new OscP5(this, "192.168.1.54", 2300, OscP5.TCP);
}

void draw() {
  background(0);
}


void mousePressed() {
  oscP5tcpClient.send("#0000$'%;8V0000!", new Object[] {new Integer(1)});
}


void keyPressed() {
}

void oscEvent(OscMessage theMessage) {
  System.out.println( theMessage);
}

While not able to see the whole code I suspect now that you are not using an OSC library at all in the Arduino code. I ordered an esp32 but until receiving, I can`t test anything… I am planning to use this Arduino OSC library. You can find a UDPSendMessage.ino in the examples. You also need the MAC address which you can obtain with code below.

#include "WiFi.h"
 
void setup(){
  Serial.begin(115200);
  WiFi.mode(WIFI_MODE_STA);
  Serial.println(WiFi.macAddress());
}
 
void loop(){}