Android script/app for redirecting USB-Serial traffic to server

I’m new to blynk and i’m still exploring the options, but i’m quite sure that the possibility of using an android device (e.g. spare cell phone) as the redirecting device of commands is missing. I would imagine an app for the purpose, but if only a script would be available next to the windows and linux/osX alternatives would be highly appreciated as well :smile:
Is it just me who thought about using a phone instead of a PC for this? Or is there an other way, what i haven’t discovered so far?
Thanks in advance for the constructive comments :wink:

I know where you are coming from and agree a ‘Computer’ is overkill for Blynk.

That is why people are using $3 ESP’s and $4 Pi Zero’s etc.

Yes, that sounds reasonable. Although, why spend money if I already have the ingredients?

@wpeti I’ll give you $10 for your old Android phone and then you can set up 2 Blynk systems with ESP / Zero :grinning:

For the product we are developing our clients wouldn’t entertain the cost of a ‘PC’ including the running cost.

You are right, especially for users that don’t want to get too technical with ESP’s and Zero’s.
I’m not a big fan of Android per se due to the restricted access that is provided to the OS without rooting the devices. I also don’t have a clue how to code for Android devices.

I do know a decent Android coder though so I will run it by him. Certainly worth the Blynk guys looking into it as fundamentally Blynk is after all an Android app (technically an iOS app too).

What do you think @Pavel, easy enough to do?

Do you mean running Blynk server on the smartphone?

No, Android providing internet connection for cloud access and then USB from Android to device.

I don’t think having wires between smartphone and the hardware is a great idea. One day everything will be wireless anyway, so why create short-term solutions? :confused:

Also, phone should be powered somehow

My idea was to use my old android phone’s features (battery, wifi, camera) combined with arduino (and some motors) to run a RC car. Because why should i buy all these components again for arduino if i have them already in the phone?
I rather think of arduino as an extension to the phone, or an interface to interact with motors and other stuff and use the phone to do the communication and video transfer part, since it’s kind of build for that.
So i’m not really thinking about the future here, just a small home project, which would be done very easily if the scripts which are available for PC, Linux and OSx would be there for Andoid as well.

Ah, I see. Then you should look for apps working over OTG cable. Blynk was designed for wireless communication primarily, for IoT

Thank you for the answers! :sunny:

@wpeti socat is available for Android so you should be able to use your old Android phone as the Gateway.

1 Like

Ok, I’ll give that a try! Thanks for the good hint!!

So the command what i made up (based on the linux script of redirection) was this:

sudo socat -d -d FILE:/dev/bus/usb/001/002,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 openssl-connect:cloud.blynk.cc:8441,nodelay

Ufortunately in response i get the below, error:

2016/01/25 21:27:35 socat[12145.12288000] N opening character device “/dev/bus/usb/001/002” for reading and writing
2016/01/25 21:27:35 socat[12145.12288000] E tcgetattr(4, 0xbea7e1a4): Inappropriate ioctl for device
2016/01/25 21:27:35 socat[12145.12288000] N exit (1)

And now i’m pretty much stuck since i have no idea what could be wrong… the error is magnificently informative.
I think i’ll try to dig up the manual of this socat thingy.

Managed to squeeze out a more detailed log:

2016/01/25 21:39:34 socat[13549.4194304] D getpid()
2016/01/25 21:39:34 socat[13549.4194304] D getpid() → 135492016/01/25 21:39:34 socat[13549.4194304] D setenv(“SOCAT_PID”, “13549”, 1)
2016/01/25 21:39:34 socat[13549.4194304] D setenv() → 0
2016/01/25 21:39:34 socat[13549.4194304] D setenv(“SOCAT_PPID”, “13549”, 1)
2016/01/25 21:39:34 socat[13549.4194304] D setenv() → 0
2016/01/25 21:39:34 socat[13549.4194304] I socat by Gerhard Rieger - see www.dest-unreach.org
2016/01/25 21:39:34 socat[13549.4194304] D socat version 2.0.0-b7 on Apr 12 2014 17:55:46
2016/01/25 21:39:34 socat[13549.4194304] D setenv(“SOCAT_VERSION”, “2.0.0-b7”, 1)
2016/01/25 21:39:34 socat[13549.4194304] D setenv() → 0
2016/01/25 21:39:34 socat[13549.4194304] D running on Linux version #1 SMP PREEMPT Thu Feb 26 20:21:33 KST 2015, release 3.4.5-3943544, machine armv7l

2016/01/25 21:39:34 socat[13549.4194304] D argv[0]: “socat”
2016/01/25 21:39:34 socat[13549.4194304] D argv[1]: “-d”
2016/01/25 21:39:34 socat[13549.4194304] D argv[2]: “-d”
2016/01/25 21:39:34 socat[13549.4194304] D argv[3]: “-d”
2016/01/25 21:39:34 socat[13549.4194304] D argv[4]: “-d”
2016/01/25 21:39:34 socat[13549.4194304] D argv[5]: “FILE:/dev/bus/usb/001/002,raw,echo=0,clocal=1,cs8,nonblock=1,b9600"2016/01/25 21:39:34 socat[13549.4194304] D argv[6]: “openssl-connect:cloud.blynk.cc:8441,nodelay”
2016/01/25 21:39:34 socat[13549.4194304] D signal(1, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(2, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(3, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(4, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(7, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(8, 0xa588)2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(11, 0xa588)
2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D signal(15, 0xa588)
2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] D sigaction(10, 0xbeea23f4, (nil))
2016/01/25 21:39:34 socat[13549.4194304] D sigaction() → 0
2016/01/25 21:39:34 socat[13549.4194304] D atexit(0xa634)
2016/01/25 21:39:34 socat[13549.4194304] D atexit() → 0
2016/01/25 21:39:34 socat[13549.4194304] D signal(13, 0x1)
2016/01/25 21:39:34 socat[13549.4194304] D signal() → (nil)2016/01/25 21:39:34 socat[13549.4194304] I opening address “FILE:/dev/bus/usb/001/002,raw,echo=0,clocal=1,cs8,nonblock=1,b9600”, rw=2, flags=0x2c
2016/01/25 21:39:34 socat[13549.4194304] D calloc(1, 744)
2016/01/25 21:39:34 socat[13549.4194304] D calloc() → 0x401938
2016/01/25 21:39:34 socat[13549.4194304] D malloc(832)
2016/01/25 21:39:34 socat[13549.4194304] D malloc() → 0x401c48
2016/01/25 21:39:34 socat[13549.4194304] I setting option “raw”
2016/01/25 21:39:34 socat[13549.4194304] I setting option “echo” to 0
2016/01/25 21:39:34 socat[13549.4194304] I setting option “clocal” to 1
2016/01/25 21:39:34 socat[13549.4194304] I setting option “cs8”
2016/01/25 21:39:34 socat[13549.4194304] I setting option “o-nonblock” to 1
2016/01/25 21:39:34 socat[13549.4194304] I setting option “b9600”
2016/01/25 21:39:34 socat[13549.4194304] D searching record for “open” with tag=0, numparams=1, leftdir 4, rightdir 0
2016/01/25 21:39:34 socat[13549.4194304] D selected record with leftdirs 7
2016/01/25 21:39:34 socat[13549.4194304] D stat64(/dev/bus/usb/001/002, 0xbeea2240)
2016/01/25 21:39:34 socat[13549.4194304] D stat64(, {12,4064,020660,1,0,1018,48385,0,4096,0,…}) → 0
2016/01/25 21:39:34 socat[13549.4194304] D _groupbits(8624) → 65536
2016/01/25 21:39:34 socat[13549.4194304] N opening character device “/dev/bus/usb/001/002” for reading and writing
2016/01/25 21:39:34 socat[13549.4194304] D open(”/dev/bus/usb/001/002", 04002, 0666)
2016/01/25 21:39:34 socat[13549.4194304] I open(“/dev/bus/usb/001/002”, 04002, 0666) → 4
2016/01/25 21:39:34 socat[13549.4194304] D isatty(4)
2016/01/25 21:39:34 socat[13549.4194304] D isatty() → 0
2016/01/25 21:39:34 socat[13549.4194304] D tcgetattr(4, 0xbeea2194)
2016/01/25 21:39:34 socat[13549.4194304] D tcgetattr(, {32203532,39333a31,2034333a,61636f73,5b,31,33,35,34,39,2e,34,31,39,34,33,30,34,5d,20,44,20,73,69,67,6e,61,6c,28,29,20,2d,3e,20,28,6e}) → -1
> 2016/01/25 21:39:34 socat[13549.4194304] E tcgetattr(4, 0xbeea2194): Inappropriate ioctl for device
2016/01/25 21:39:34 socat[13549.4194304] N exit(1)
2016/01/25 21:39:34 socat[13549.4194304] I close(4)
2016/01/25 21:39:34 socat[13549.4194304] D close() → 0
2016/01/25 21:39:34 socat[13549.4194304] I close(4)
2016/01/25 21:39:34 socat[13549.4194304] D close() → -1
> 2016/01/25 21:39:34 socat[13549.4194304] I close(4): Bad file descriptor

@wpeti I have added socat to my Android and I have the same errors as you.

Having accessed the Arduino USB port via Kodi on an Android device I have encountered similar problems previously. I am just checking some of my files but the workaround for Kodi was to use a little utility to open the serial port on the Android device before running Kodi. The utility was written by the guy that wrote DroidTerm. I think DroidTerm or the SerialPort utility might be needed alongside socat.

Which Arduino’s are you using and specifically with USB chip (Nano clones are generally CH340 and the DroidTem author added support for this chip last year)?

Will get back to you if I find a fix.

@Costas Thanks for the verifictaion :slight_smile:

I’ll check out the port opening theory afternoon. Until then, I’ve found this information on Arduino Uno R3’s description site:
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 programmed as a USB-to-serial converter.

Does the type of the chip has any effect on how it should be connected?

Considering android are plenty of sensors (GPS, motion…)
Can android cellphones be recognized as hardware providing sensor output information?