Fun taking pictures with DevConsole

The Sonix board dev console can be accessed at 192.168.99.1 and port 2017, with telnet or better yet netcat. (netcat 192.168.99.1 2017). You’ll see a list of available commands there if you type help at the dev> prompt, including the “snapshot” command for taking a snapshot

Here’s one fun hack: automatically take pictures, in this example 100, roughly one per second. Done here as a quick example with tcl/tk expect and a shell script, but lots of ways to do it, with python and pexpect module, programming the web server, etc …

On Linux Ubuntu, install expect if you don’t have it:: > sudo apt- get install expect. This should be possible in windows too as both netcat and expect are available, but I haven’t tried it,

Write the following in, say, snap.exp, replacing the 4th line up to \r with exactly what you seen when you nc into the console. (your compile time and fd will differ).

#!/usr/bin/expect
spawn nc 192.168.99.1 2017
sleep 0.25
expect "Dev console start (compiled Oct 23 2017 17:04:30) fd=12\r
dev> "
sleep 0.25
send "snapshot\r"
sleep 0.5
send "^C"

and the following in, say, snaps,sh:

!/bin/bash
numpics=1
while [ $numpics -le 100 ]
do
    echo "Taking picture" $numpics
    ./snap.exp > /dev/null
    ((numpics++))
done

Now point your web browser to http://192.168.99.104/filesystem.html, move to the SKYVIPER/Photos directory, execute ./snaps.sh on terminal, and watch that SD card fill up with pictures!

This is of course very rudimentary, but not bad for less than 20 lines of simple code :slight_smile:

Note for developers:

  • You can access additional commands with the sys command, including setting debugging options. There are multiple levels and choices once you hit sys with an option, with additional options at each.

  • For the curious, to use the tasks command, you will need to build a kernel (see wiki, building Sonix firmware) with trace enabled. Quick and dirty way. Edit .config in Sonix/buildscript, delete lines containing TRACE and RESCUE, and run make oldconfig. When prompted select yes for TRACE enable, and pass on RESCUE. (firmware doesn’t build otherwise).

  • See also README and devconsole.c

1 Like

Thanks Olivier!
You can also take photos with wget like this:
wget 'http://192.168.99.1/ajax/command.json?command1=take_picture()'
For more details on other fun things you can do with the JSON interface see this doc:
https://docs.google.com/document/d/1ulqP7QcROBAOAnX_B8jhXISB-__hJvYlzP9stExI5vU/edit?usp=sharing
That protocol gives you full MAVLink access, as well as access to special Sonix functions (like controlling photos and videos).
Cheers, Tridge

here’s a challenge for you, work out the right wget command to get the TX to play a christmas carol.

Ha, better and even easier… Now less than 10 lines of code! :wink:
Thanks for the doc!

It’s amazing what that environment and interface can do, I can imagine a full blown web server with all sorts of commands and bells and whistles …

On another note, I’ve been looking into finding what happens when a file of more than 2MB or so is uploaded. When that’s the case the upload command doesn’t complete and connection is lost . As you mentioned the other day the system must be running out of memory, but I haven’t been able to figure out where so that it could be made to return with an error (replace unused result
var with, say, a set_upload_message()) and without a connection break. Doesn’t look like it’s in a failed fopen() nor it makes it to fwrite() or talloc() (oldie but goldie, eh? ;))…

Anyways, I am having fun coming to grips with the Sonix environment, FreeRTOS and tracing!

It is this line:
https://github.com/SkyRocketToys/Sonix/blob/master/app/dashcam/src/main_flow/ArduPilot/web_server/cgi.c#L239
you’d need to teach the multi-part upload to write straight to the filesystem instead of loading it all to memory then saving. Quite possible, just needs some restructuring.
I’m curious though, what sort of large file do you want to upload?
Cheers, Tridge

Hey, I was getting close! :slight_smile:

None, really. Also why I don’t think it’s a big deal.
I’ve was just fooling around with the interface when I noticed it, also testing wifi speeds.

1 Like