TCP/IP Extension

Hello man,
I appreciate your work but i have an issue

  • when i tried to work with another screen i couldn't able to achieve the communication, It shows that socket not connected. but if i switch to the screen1 i can make communication.
    What would be the reason for this?

I will be thankful if you solve my issue :handshake:.

My aia file:
TestSocket_copy.aia (21.1 KB)
Screenshots of the error:


Hello,
This problem is not a problem with my extension, but with the way app inventor implements screens. You cannot share variables other than simple ones (int or strings or maybe lists but not complete extensions) between screens. Two choices :

  • either, instead of using screens, use the visible property of every widget to modify the screen appearance ;
  • or use a database to pass data useful for the extension (IP address, port, connected or not) with tinyDB (http://www.appinventor.org/content/howDoYou/screens/share) between screens, and when changing screen, close the socket on the quitting screen and re-open it on the arriving screen (if connected).
    I confronted myself with exactly the same problem as you, and depending on the project, I used one solution or the other.

Got your point :slightly_smiling_face: and Thank you soo much for your concern within less time :handshake:.

Hello,
I think I have an ESP 8266 hanging around here, when I will have time I will try to reproduce the error that you raised and try to correct it. As always, no estimated time of achievement of a corrected extension ... will post it here as soon as I find the problem.

You can also just turn WiFi off in your mobile after you connect to a tcp server.

Thx for suggestion, will be easier to test.

What does your client web server look like that answers the socket? Do you just listen on the port or do you need to add the websocket handshake scripting? I'm confused on how the javascript handshake relates to what is sent from Kodular.

Hola, Estoy mirando la Extensión y probando.

Logro conectarme a un servidor mediante TCP una conexion de escucha, y se logra!, pero entonces, no le puedo enviar mensajes, ya que me llegan los mensajes en BLANCO, la conexion se efectua para enviar el mensaje y mi servidor de escucha la detecta, pero no llega ninguna información en la conexion realizada. Alguna idea de por qué?

Hi,
Thnaks for sharing your great work. TCP socket is working very well, only thing is that when i am sending data from arduino to Test socket it is receiving all the characters except first. But when i receive the same data in other TCP terminals, i am getting all the characters.
Thnaks

Hi everyone,
I am using TCP/IP extension by Jean-Rodolphe_Letert. TCP socket which is working fine, only thing is that when i am sending data from arduino to Test socket it is receiving all the characters except first. But when i receive the same data in other TCP terminals, i am getting all the characters. Can anybody help please.
Thnaks

Hello,
Will investigate on this but I don't have much time to work on it, so I cannot give you an ETA ...
Cheers

Just looked at the java program ... can you tell me what is the first character lost ? is it always the same ? do you use hexaStringMode ?

Hi,
I am not using hexa mode and always missing the characters.
When i run below Arduino sketch, first couple of characters are always missing in TCP socket but not in other TCP terminals (checked with TCP client and TCP Terminal from play store).

const int potmeter1 = 0; 
      void setup() {
      pinMode(potmeter1, INPUT);
      pinMode(potmeter2, INPUT);
      Serial.begin(115200);
      tcp.begin(115200);
    }
      void loop() {
      char c=tcp.read();
      int potValue1 = analogRead(potmeter1); 
      potValue1 = map(potValue1, 0, 1023, 0, 1023);  //First potmeter mapped between 0 and 1023    
      tcp.print(potValue1);   
      }

------------
I foun that i i add empty line or 1 or 2 char before the potvalue , then tcp client will receive all the char of pot value without empty spaces or extra added char. modified sketch below.

const int potmeter1 = 0; 
      void setup() {
      pinMode(potmeter1, INPUT);
      pinMode(potmeter2, INPUT);
      Serial.begin(115200);
      tcp.begin(115200);
    }
      void loop() {
      char c=tcp.read();
      int potValue1 = analogRead(potmeter1); 
      potValue1 = map(potValue1, 0, 1023, 0, 1023);  

       tcp.print("             ");     // or tcp.print("a");   
      tcp.print(potValue1);   
      }

Thanks

Hi Jean-Rodolphe,

First of all thanks for the code that you provided!

I have a similar problem as others already reported that the FIRST character is missing when sending from ESP => App. For me it is only the first character, not several - So if I send "Test" from the Arduino IDE Serial Monitor I only receive "est" in the aia demo app.
It seems to have a similar behavior if I enable the Hexa String Mode - if I just transmit a single character the received text in the App is always "0D0A" - and this is independent of what single character I transmit.

For the moment I could workaround by always sending a dummy character as first character (e.g. "XTest") - however would be great if this would be working as intended.

Let me know if you want to debug this with me in a shared session...

Tobi

Excelent. Thanks for sharing.

how to replace the 2000 ms timeout time with another duration?

Hi thanks for the code.

How can i disable the error messages?

Thanks

Hello ;
I want to send data for a specific address at the plc register. I can connect to the my plc's HMI screen, thanks to your extension with TCP/IP. But I want to send a data to register adress. Do you have a any recommendation.

Hi Jean,

Great Extention exactly what I was looking for. :grin: :grin: :grin:

I tried using the Hexa mode, but noticed that when I send 123 "303132" on the receiving side I'm getting "30 31 32 00". I am always getting a null character added at the end of the message; which I do not want and will mess up things on the receiving side which I have no control off.

If I send "52" I'm receiving "52 00"

Is the null character coming from the Extention or ???, and is it possible to get rid of it. It only occurs when using the Hexmode... Or can we toggle on/off if needed for other scenarios...

TIA

Hello,
Sorry for not answering for a long time.
I don't know why this is happening because on my phone and with the basic project, there is no problem, I choose Hexa String Mode and send 303132, I receive on the other side 303132.
Here is a version of the extension with app inventor sources updated, can you try it and tell me if it make it works better ?

com.gmail.at.moicjarod.aix (18.3 KB)