Tuesday, June 16, 2020

Flashing ArduPlane or iNav firmware to flight controllers using BetaFlight

Some quadcopter flight controllers can be used on fixed wing aircraft using iNav (which supports more targets, and is based on BetaFlight) and ArduPilot/ArduPlane. 

Before buying, MAKE SURE the FC is supported.  For example, I purchased two F722 boards... which is not the same as F7 v2, which has more memory.  Poof there goes $64.

ARDUPILOT
Go to ardupilot.org
Downloads > Firmware
Select plane (not copter or anytnign else)
Choose latest stable release eg stable-4.0.5
Choose your flight controller
download the ardupilot_with_bl.hex file

iNav is similar.  Note, although iNav supposedly can flash firmware, on versions newer than 2.0 flashing doesn't work on MacOs.  So I was back to BetaFlight.

PROCEDURE
hold down boot button on the board as you plug it into USB on your computer
start Betaflight
select DFU as the port if not selected
go to the firmware flasher tab
load firmware [local]
select arduplane with bl or the inav firmware .hex file
make sure no reboot sequence is selected (otherwise BF will show it is erasing, finish, and get stuck at the flashing step)

Now flash and hopefully you get PROGRAMMING: SUCCESSFUL

If not, try with full chip erase disabled.  If flashing gets stuck, close Betaflight and re-open it and try again.

You can always re-load the BF firmware this way too.

Thursday, October 01, 2015

Capturing an Image from a Security Camera Using Vera and Emailing It

I wanted to get my VeraLite home automation gateway to grab a frame from a security camera and email it to me whenever the front door opening scene runs.  Without going into extreme detail, I found that I needed to use another computer (an old Thinkpad with Ubuntu) to do the heavy lifting.  The process is as follows:

1) Enable SSH access on the Vera.  You need to enable remote access and make sure secure my vera is disabled and then SSH to remote@your-vera-local-ip-here with the second, six digit number that appears when you enable remote access under the Vera's Settings > Tech Support menu.

2) Setup the Vera to login without a password to your Linux server.  There's a big gotcha here in that YOU login to the Vera using remote, but scenes run under a different user so the keystore needs to be linked or copied to both accounts.  Here's how to setup the keys: http://forum.micasaverde.com/index.php?topic=11663.0 and here's how to do the linking of the keystore: http://forum.micasaverde.com/index.php?topic=11663.15

3) Create a shell script to call a script on your Linux server.  Avoid trying to make SSH calls within the scene's Luup code -- it's a nightmare of semicolons and escape characters.  For example, my verafrontdoor.sh script looks like: 
#!/bin/sh
echo "Started" > /root/frontdoor.log
ssh -i /root/.ssh/id_dss -l yourusername YOUR_LINUX_SERVER_IP '~/capturefrontdoor.sh' >> /root/frontdoor.log 2>&1
echo "Finished" >> /root/frontdoor.log


Don't forget to chmod +x verafrontdoor.sh so it's executable

4) Go into the Vera web panel and edit your scene.  The last window allows you to put custom Luup code.  GOTCHA: this Luup code has to execute within 30 seconds unless you use a workaround.  Capturing and emailing the picture takes longer than that for me possibly, so the workaround is to use call_delay as below:
function callssh()
os.execute(‘/root/verafrontdoor.sh’)
end
luup.log("Calling SSH function")
luup.call_delay("callssh", 1)
luup.log("ssh call done")

5) Now on the Linux server side, create capturefrontdoor.sh.  You will need to Google around to figure out if your camera supports grabbing a JPEG via a simple wget call.  If not, but it supports RTSP streams, find out the RTSP url and try to open it using VLC Player.  If that works, install FFMpeg (or, on Ubuntu 12, download an FFMpeg static build since FFMpeg is missing from the repos) and grab a frame this way.  Here's the call:
./ffmpeg -rtsp_transport tcp -i rtsp://user:password@CAMERA_IP:CAMERA_RTSP_PORT/path/to/stream -y -f image2 -qscale 0 -frames 1 -analyzeduration 5 frontdoor.jpeg

QScale keeps the quality the same, -f image2 saves as a JPEG, -rtsp_transport_tcp ensures packets come back in the correct order (default is UDP which can be unordered, causing a garbled image), and analyzeduration means FFMpeg grabs several seconds of video before making the grab.  You'll have to tune it for your camera.

6) Rather than properly setup sendmail, I wanted to use Gmail.  I installed mailx using apt-get but kept getting errors that Gmail was blocking potentially malicious access to my email account.  You need to turn on access for "less secure" apps. See https://www.drupal.org/node/2080923

For setting up mailx to use Gmail, see http://www.absolutelytech.com/2010/07/17/howto-configure-msmtp-to-work-with-gmail-on-linux/

7) Complete your Linux side script.  It's handy to pipe the output of ffmpeg to a log file as well.

8) RUN THE SCRIPT ON THE VERA MANUALLY AT LEAST ONCE.

9) Execute your scene and verify it works.  

#homeautomation #diy #securitysystems #linux 

Monday, February 23, 2015

Javascript Namespaces

Google "namespace" and "javascript" and you'll get a lot of different approaches to the solution, since vanilla Javascript doesn't provide out of the box namespaces.  Here's how jQuery and others do it.  If you want the quick answers, you can skip the link and just copy paste from below. The solution is to create an anonymous function and call it immediately, associating it with the Javascript window object.

A few notes from me:


  1. My library doesn't load correctly.

    My library has some pre-reqs; the easiest solution was to wrap the declaration in jQuery's $().ready().  See below.  There are other better solutions for Javascript dependency management, but they weren't necessary.
  2. This is great, but underscore templating doesn't work INSIDE the namespace?  Ahh!?! What do I do?

    Well, here's the key parts of the sample solution.  Note that the function definition has three arguments.  The first is the namespace itself, then a $, then undefined.  The first argument's purpose is obvious, the last is a Javascript technicality; just include it.  You can add additional arguments in the middle. Note the call to the "namespace" function on the last line passes in jQuery for argument two, which maps jQuery to $.

    (function( skillet, $, undefined ) {
       //stuff
    }( window.skillet = window.skillet || {}, jQuery ));

    So if you want to use jQuery AND underscore, or any library for that matter, you'll have to add arguments to the definition and function call.  For openbrewery, the namespace declaration looks like this, defining and passing both $/jQuery and _/underscore:
    $().ready(function() {
       (function( openbrewery, $, _, undefined ) {
          //Stuff
       }( window.openbrewery = window.openbrewery || {}, jQuery, _ ));
    });


Tuesday, January 27, 2015

GPhoto2 Notes

Using Canon A620 with Ubuntu 12.04 LTS

sudo apt-get install gphoto2

Plug in the camera via USB
Set camera to review mode (this camera only connects via PTP, has to be in review mode to activate this)
Docs say to click the PTPbutton but not needed

From command line:
gphoto2 --list-ports
Lists all possible ports gphoto2 could connect on.   Interesting, but I sure hoped I didn't have to use it.

gphoto2 --autodetect
Tries to autodetect the camera.  Luckily this worked for the A620.

gphoto2 --list-config
Lists all the configuration items that can be viewed/edited.

gphoto2 --get-config={listed config item]
Only ones that were interesting to me were mode (Auto/Tv/Av/Manual) and afdistance.  You can't actually control the focus.  For my application, I set the camera to program mode and set to infinity focus from the interface.

gphoto2 --set-config=item=value
Goofy syntax.  For example, gphoto2 --set-config=afdistance=0

gphoto2 --capture-image
Save photo to SD card.

gphoto2 --capture-image-and-download 
Save photo to local device. Can also add -filename blah.jpg afterward to specify filename.  Behind the scenes, I think this takes a picture to the SD card, copies it, and then deletes the file.  

During image capture, despite the camera being in review mode, the camera lens comes out and it takes a picture.

Friday, April 04, 2014

Running Python Scripts on Arduino Yun

Completely inexplicably, I am unable to find an example of running a python script using the Bridge library in the official Arduino Yun documentation, despite this being a main selling point of using the Yun.

What You Need to Know Beforehand

Python scripts in the www directory of your sketch get uploaded to /mnt/sd/arduino/www/YOUR_SKETCH_NAME_HERE
on the Yun.

However, when you create a process on the ATMega using the bridge library, it does not appear to run from that directory automatically, so you will need to provide a full path to your python script.

Additionally, output from stdout is captured by the bridge library and can be read on the ATMega side, but error output is NOT.  You can fix this by adding an additional parameter &2>1.  See below.

Below is an example.
Process p;
p.begin("python");
p.addParameter("/mnt/sd/arduino/www/mysketch/myscript.py");
p.addParameter("foo"); // A command line parameter for the script
p.addParameter("&2>1"); // pipe error output to stdout
p.run(); // blocking call to run python; ATMega execution halts until complete

while(p.available()>0) {
    Console.print(p.read());
}

runShellCommand() is Funky

I initially tried p.runShellCommand(), however, this did not appear to work reliably.  Some Python scripts ran, others didn't, and there was no error output available.  The only difference that I could discern between scripts that did work and that didn't was the length of the command string.  The documentation doesn't state any specific length limit.  I don't know.

How do I know if My Script Ran?

I took a simple approach; the very beginning of my Python script writes to a file.
file = open("/mnt/sd/arduino/www/mysketch/i_ran_yo.txt", "w")
file.write("code ran\n")
file.close()
Check the date on that script using "ls -l" to see if you're python script has been called.

The Arduino Documentation for available() is Wrong

p.available() returns the number of characters of script output that are available.  The documentation says if none are available, the script returns -1.  This is incorrect.  It returns 0.

Outstanding Questions

Does the blocking call to run() have any effect on interrupt handlers?

Dear Arduino Team

Please provide more complete documentation (or let us edit it somehow so we can fix it) and error logging in the bridge library.  

Tuesday, March 25, 2014

JSON REST Webservice Error Responses

Over the years I've seen many formats for error responses from JSON formatted REST webservices.  Well, there's a draft standard.

The quick answer is:

Error Response

In the event of an error, a 4xx or 5xx HTTP status code SHOULD BE expressed in the response, with an entity body containing an error object adhering to the following structure: { "error": number, "reason": string, "detail": string }

Thursday, March 20, 2014

Getting Started with Python on Windows

I'll be using Python on the Arduino Yun, but wanted to develop scripts on my Windows machine.  Need Python + the pip package manager (to install add on modules).
  1. Install Python (Yun uses 2.7): https://www.python.org/download/ 
  2. Install setuptools: http://www.lfd.uci.edu/~gohlke/pythonlibs/#setuptools
  3. Install pip: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip
Now you can start a shell by navigating to Start>Python 2.7>IDLE 

Install add ons by starting a Windows command shell (Windows+R and type cmd.exe and press enter).  CD to your Python install directory (C:\Python27 by default).  CD Scripts.  Then you can type something along the lines of:
pip install git+https://github.com/dgrtwo/ParsePy.git

And it will just magically install (hopefully).

Tuesday, December 17, 2013

ReCaptcha and PHP

Had to load ReCaptcha in a PHP page-- with ajax.  Two sources made this possible:

https://developers.google.com/recaptcha/docs/display
http://stackoverflow.com/questions/7261436/how-can-i-load-a-recaptcha-form-using-jquery-ajax-while-leaving-the-recaptcha-sc

I set it up such that I have recaptcha.php (which is the library) and my index.php.  Head on over to the recaptcha page to generate a key pair if you haven't already, by the way.

Include a script tag to load recaptcha_ajax.js
On document.ready, use recaptcha.create.  one of the arguments is a form on your page to add recaptcha to.

Your form can submit via ajax to another php page.  Just use the code block from the recaptcha library to check whether recaptcha succeeded.  If not, do something like:

header("HTTP/1.1 500 Internal Server Error");

Thursday, March 21, 2013

Creating an Ubuntu VMware player virtual machine for Java Development

Four major steps:

  1. Install Ubuntu
  2. Install Java
  3. Instal Maven (ugh)
  4. Install git
  5. Install Eclipse
Ok, let's get to it.

Ubuntu

Create a new VM in VMWare Player and choose the iso file you downloaded from Ubuntu.  
Set memory to 2gb or you'll live in a world of pain.

Now setup VMWare tools, which won't install correctly until you follow this:
http://askubuntu.com/questions/131351/how-to-install-vmware-tools

Basically, type
sudo apt-get install build-essential linux-headers-$(uname -r)

Then install vmware tools by typing
vmware-config-tools.pl

Accept all the defaults.

Java

Installing Java is well documented as the answer at this URL:

Maven

Maven is the philosophical opposite of Ubuntu so installing it feels a bit like taking a dump on an altar, but many Java projects use it anyway.  Luckily, the install is the least painful thing about Maven (well, as long as you're not using Windows).
sudo apt-get install maven

git

Just follow the bitbucket instructions.  Easy.

Eclipse

Installing the base Eclipse is easy except for the icon.  I won't get into all the plugins you actually need to do work and the hell which can come out of that...
Download Eclipse here.
Open a terminal (click the Ubuntu logo in the upper left and type term and then click the terminal application that appears)
cd ~/Downloads
tar -xvf eclipsefilenamegoeshere.tar.gz
./eclipse &

Eclipse will now launch and a blank icon will appear in the launcher.  If you'd like to fix this, follow these instructions.


Tuesday, March 05, 2013

Adding Modules to Alfresco 4.x

FYI I'm using the Bitnami AMI.

Download and move the module:

  1. cd ~/
  2. wget http://path/to/alfresco_amp_module
  3. sudo mv ~/module.amp /opt/bitnami/apps/alfresco/amps/
  4. sudo /opt/bitnami/ctlscript.sh stop
  5. cd /opt/bitnami/apps/alfresco

Install module: sudo ./apply_amps.sh
(accept the prompts)

Verify module is installed: sudo java -jar alfresco-mmt.jar list /opt/bitnami/apache-tomcat/webapps/alfresco.war

Start up Alfresco again:
sudo /opt/bitnami/ctlscript.sh start

Labels

Blog Archive

Contributors