Problems receiveing HTTP on Android with loadstrings

Hi,
I have set up on my Adruino ESP32 a AccessPoint. It works and will receive informations over the browser on my android. For example:

192.168.4.1/red=on

Will turn on the red LED on my ardunio. Now I want to send ColorInfomations over this connection. Therfore I have a Color-Picker on my Android and a Servo which can be controlled over the app.

This is the code:


void setup() {
  size(540, 960);
  frameRate(10);
  servoPlusButton = new Button("servo +", width+10);
  servoPlusButton.setAction(new ServoPlusAction());
  servoMinusButton = new Button("servo -", width+190);
  servoMinusButton.setAction(new ServoMinusAction());
  colorPicker = new ColorPicker();
  colorPicker.setImage("colorwheel.png");
  colorPicker.setAction(new ColorChangeAction());
}
// -------------------------------------------------- 
void draw() {
  background(red, green, blue);
  servoPlusButton.draw();
  servoMinusButton.draw();
  colorPicker.draw();
  showValue(servo, "Servo", width+100);
}
// -------------------------------------------------- 
void mousePressed() {
  servoPlusButton.update();
  servoMinusButton.update();
  colorPicker.update();
}
void showValue(float val, String label, int yPos) {
  fill(255);
    rect(0, yPos, width, 80);
    fill(0);
    textSize(30);
    textAlign(CENTER, CENTER);
    text(label + ": " +val, 0, yPos, width, 80);
}
// -------------------------------------------------- 
void sendValues() {
  try {
    loadStrings("http://" + ip 
    + "/red/" + red 
    + "/green/" + green 
    + "/blue/" + blue
    + "/servo/" + servo);
  } 
  catch (Exception e) {}
}

void sendValues should sent the parameters to my arduino but the app dont.
In my browser on Android it works.

Can you help me?

hi,
the title looks like you want send to android ( not from ),
but in the text you suggest you talk to a local web server ESP32 AP mode

where is the servo connected?

the code can not be complete, any libraries??

on the first look i can not see where you call

sendValues()

just for a diagnostic it could help to first build the string, print it
and then send it.

String send = “http://” + ip
+ “/red/” + red
+ “/green/” + green
+ “/blue/” + blue
+ “/servo/” + servo;
println(send);
loadStrings(send);

you explain you want send

192.168.4.1/red=on

but send

http://192.168.4.1/red/255/green/255/blue/255/servo/123

that might be difficult to HTTP GET split

for develop i would not go the long way to make a android app,
just a 5 line processing code on the PC
to talk to the ESP


pls also repair above code posting and use the

</> code formatter

Thank you.

I want to send from android to my ESP32 AP. The servo is to the arduino connected. Ther were no libraries.

Yes, the code is from the Make-Magazin and the arduino part should use a wifi router. I changed the code for the arduino part to be a access point. This works.

The app send:
http://192.168.4.1/red/255/green/255/blue/255/servo/123

but in the serial monitor of the arduino ide nothing would be received. If i post the link in the browser on android, I receive it in the serial monitor. So I thought the app wont send anything.

pls. again:
-a- where you call that

sendValues();

from?
-b- did you try my idea with the make String send
and print it first ( so you see the send is attempted and the string is good.
-c- i not see where any of that 4 variables are defined,
can you test first with a fix string “send”
make sure “ip” is a string and not a tuple
-d- just to be sure the loadStrings works better use the correct syntax:

    println("string: "+send);
    String[] lines = loadStrings(send);
    println("return:");
    println(lines);

OK, sorry I forgott the code.

abstract class Action {
  abstract void go();
}
// --------------------------------------------------
class ServoPlusAction extends Action {
  void go() {
    servo = constrain(servo+5, 0, 180);
    thread("sendValues");
  }
}

class ServoMinusAction extends Action {
  void go() {
    servo = constrain(servo-5, 0, 180);
    thread("sendValues");
  }
}
// --------------------------------------------------
class ColorChangeAction extends Action {
  void go() {
    thread("sendValues");
  }
}

class Button {
  String label;
  int yPos, ySize = 80;
  Action action;
// --------------------------------------------------   
  Button(String label, int yPos) {
    this.label = label;
    this.yPos = yPos;
  }
// --------------------------------------------------   
  void setAction(Action action) {
    this.action = action;
  }
// --------------------------------------------------   
  void update() { 
    if (mouseInside()) {
      action.go();
    }
  }
 
  boolean mouseInside() { 
    return mouseX > 0
      && mouseX < width
      && mouseY > yPos
      && mouseY < yPos + ySize;
  }
// --------------------------------------------------   
  void draw() {
    fill(255);
    rect(0, yPos, width, ySize);
    fill(0);
    textSize(30);
    textAlign(CENTER, CENTER);
    text(label, 0, yPos, width, ySize);
  }
}

class ColorPicker {
  PImage img;
  int x, y;
  Action action;
// --------------------------------------------------  
  void setImage(String path) {
    img = loadImage(path);
  }
// --------------------------------------------------  
  void setAction(Action action) {
    this.action = action;
  }
// --------------------------------------------------  
  void update() {
    if(mouseInside()) {
    loadPixels(); 
    color c = pixels[mouseY * width + mouseX]; 
    x = mouseX;
    y = mouseY;
    red = red(c); 
    green = green(c);
    blue = blue(c);
    action.go(); 
    }
  }
 
  boolean mouseInside() { 
    return mouseX < width
      && mouseY < width;
  }
// --------------------------------------------------  
  void draw() {
    image(img, 0, 0, width, width);
    ellipseMode(CENTER);
    fill(red, green, blue);
    ellipse(x,y,20,20);
  }
}

In Processing they were parts of the project.

Thank you your code works.

Dont work again???

Got the error:

java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1202)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:966)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at processing.core.PApplet.createInputRaw(PApplet.java:7058)
at processing.core.PApplet.createInput(PApplet.java:7011)
at processing.core.PApplet.loadStrings(PApplet.java:7465)
at farbzeiger.sendValues(farbzeiger.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet.method(PApplet.java:3742)
at processing.core.PApplet$2.run(PApplet.java:3780)
The file “http://192.168.4.1/red/223.0/green/0.0/blue/54.0/servo/0.0” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

does it never work? possibly you send too often?
because you say when you send one time manually
via browser it works?

anyhow but now we know the real thing, what that, what you send, looks like,
and i hate that you send float, does not make sense at all.
but still the question is what the webserver does with it,
so now you check again using the browser,
but give this exact string:
http://192.168.4.1/red/223.0/green/0.0/blue/54.0/servo/0.0

is there any response from the server like “OK” that the URL is understood?
does it not work but work with sending
http://192.168.4.1/red/223/green/0/blue/54/servo/0

and you must find out how often you send that,
i not see a restriction on that, so there could be flooding
as soon you touch mouse…
because you do the
action go ( via color picker.update )
and never check if the variables ( red green blue ) have changed by 1.x
also the servo looks restricted by 5, it is not, the value is restricted, the sending NOT.

can you link ( or provide ) the full code ( even the ESP32 )

HI,

I did several Tests.

I changed the android app to send only “Hello” anytime. In Procession with JAVA connected from my Mac to the Arduino AccessPoint it works. I got no error in the Processing konsole and the text will be received in the Serial Monitor on my ESP32.

Now I ported the App with Processing to my Android Phone and there it never works. Sending the same Text in Android browser get the result in the Serial Monitor.

Have you got a hint?
Thank you

I would like to clarify your setup.

  • You have arduino unit that is connected to Processing via serial

  • You have some code that you can load in a browser. The browser sends the message which is received by a Processing sketch. This sketch delivers the message to the arduino via serial monitor, correct?

  • You have also an android app made using Processing. When you send the request using your app, it does not work. This is the issue if I am following the discussion.

    • Can you tell me what permissions you enabled in your Android app?
    • Did you try running this app from the PDE while the device was still connected to your computer? Do you get any errors in the PDE console?

Kf