Trying to use TCP on my Android phone

I have an app that works fine on my PC. I’m using TCP to control some of my smart plugs over Wi-Fi instead of going through manufacturers cloud. I understand I will have to when away from home but I see much faster reaction controlling directly when I’m here.

When I try to send a command I either get toast for “The operation has timed out” or sometimes “Error…”

Should everything work on the Android the same or what do I have to do different?

Jerry

Everything should work exactly the same.

I had the port timeout value set to 1 sec so I bumped it up to 5 sec. I’m not getting the timed out error now but something new.

When I select a device that I know is online and working it doesn’t turn on or off and the tile stays “Unknown”. I can ping it from my phone so it’s out there.

When I select a device that is not online I get “No route to host” which makes sense.

Unless someone has an idea I will Wireshark later.

Jerry

Are you trying to connect directly to the IP address? Or, are you using a HostName?

I am using the IP addresses. It works from my computer is it not the same from my phone?

It should work exactly the same. I can’t explain why it works from computer & not the phone. Often these TCP services have a limit to the number of concurrent connections. There are some devices that only support 1 connection. It’s possible your phone can’t connect because the computer has an open connection. That could be the reason you aren’t able to connect.

I don’t know about the limit on connections. Even without the PC version running I have the same results.

I wanted to catch it with Wireshark and discovered my modem had a firmware update and the port mirror setup is gone. Argued with my ISP but they wouldn’t give in. I’m still checking what I can but I sure would like to see those packets.

Check everything for typos. Probably something silly. I once had an issue with an image not working on Android (worked in designer) and I found the problem was that it was case sensitive.

The odd thing is when I try a device that is offline I get a timeout error and when I try an online device I don’t get any message at all displayed. Seems like it’s sending something since it knows the offline devices aren’t there. I tried sending the data to my pc so I could Wireshark it and maybe see what’s wrong but my pc refuses the connection. The normal connection for my Kasa devices go to port 9999 but I tried 80 and 8080.

I have never checked to see if Win10 has a terminal program or I’ll find one and try that.

Discovered the problem when using my app on my phone…

I found that on the computer I can have values in my WorkArray that are greater than 127 and on the Android phone I cannot. In this code I run through my WorkArray and XOR each element with a Key to encrypt the file.

for(var x=4;x<WorkArray.length;x++){
		WorkArray[x]=WorkArray[x] ^ Key;
		Key=WorkArray[x];
		if(WorkArray[x]<0){
			TempValue=WorkArray[x];
			WorkArray[x]=(TempValue & 0x7F)+128;
		}
	}

After XOR with Key the result was always a negative value so I added the if statement to convert the value to positive, which becomes always greater than 127.

Elements [0] thru [2] are always set to 0
Element [3] always show the data length
Element [4] and on has encrypted values and the differences are shown below.

This shows the WorkArray element values ran on my phone.
Android Values

This shows the WorkArray element values ran on my PC.
PC Values

I am trying to find a way to keep the whole 8 bit value to work in my phone. In my Java version (trying to convert to use here) I cast each element with (Byte) and the Array is in the proper format to send. Is there anything like that available in JS? This is the only place I’ve used JS so I’m not familiar with it.

Jerry

1 Like

Success at last !!! and it must be a quick with Android?

Went from this

var Key= -85;

to this

var Key= 0xAB;

Now runs the same on PC and phone.