Categories
General

Logon to Linux System using SSH Private Key

You can use your public / private key pair to login to remote Linux systems without needing to remember the remote accounts password all the time.

If you already have a SSH public / private key pair on the local computer then you can skip the next step. If however you have not got one then you will need to create a pair by entering the following command:-

ssh-keygen

Now that you have a public / private key pair it can be copied to your remote Linux system using ssh-copy-id. Once this has been done you will be able to login to the remote system using your private key. This has the advantage that you do not have to remember a lot of different passwords for various machines.

Login to the Linux / OSX system you will be using normally (your local computer) and then enter the following command.

ssh-copy-id remote_user@remote_computer

Enter the password for the remote_user when prompted. Assuming that you have entered the password correctly your public key will be copied to the users account on the remote computer. You should now be able to login to that computer using your private key.

ssh remote_user@remote_computer

If you have your private key password protected (which is a good idea) then you will be prompted to enter its password.

You might be wondering where the benefit is since you still have to enter a password – the benefit comes from being able to use the same process with lots of different accounts on different machines … you now only have a single password to remember.

Categories
ATMEL General

Installing AVR Development Tools on Debian Linux

Setting up Debian Linux to develop software for the Atmel AVR microcontroller (i.e. Not Arduino) is quite straightforward and simply involves installed several packages as show below:-

  • sudo apt install binutils
  • sudo apt install gcc-avr
  • sudo apt install avr-libc
  • sudo apt install uisp
  • sudo apt install avrdude

Once this has been done a single source file containing an AVR program can be compiled for an AVR microcontroller as follows (update microcontroller to reflect the one you are using):-

avr-gcc -std=c99 -O3 -mmcu=atmega32a main.c -o main.elf
avr-objcopy -j .text -j .data -O ihex main.elf main.hex

Now connect the AVR microcontroller to your AVR programmer, and your AVR programmer to your computer. You should now be able to use avrdude to program your microcontroller.

Programming AVR using usbasp

avrdude -p m32 -c usbasp -P usb -e -U flash:w:main.hex

Programming AVR using JTAG and AVRDRAGON

avrdude -p m32 -c dragon_jtag -P usb -e -U flash:w:main.hex
Categories
ATMEL General

Re-Install AVRDRAGON Firmware

My ATMEL AVRDRAGON started responding with “bad response to enter progmode” – Unpluging the device and rebooting the computer didn’t solve the problem.

I have seen this error before however I only remembered when I found the solution again – the firmware on the dragon needs to be reflashed – I’m sure there must be another way but this seems to fix it – Hence why I am making a note of it here before it happens again.

I normally use a Linux System when developing AVR software however it is the AVRDRAGON’s firmware that needs to be re-flashed and the tool is only available on windows. Luckily I still have an old Windows machine around with Atmel Studio 7 installed.

Open up a command prompt on a Windows System containing Atmel Studio 7 – it will probably work with other versions but you will have to update the paths.

cd "c:\Program Files (x86)\Atmel\Studio\7.0\atbackend"
atfw -t avrdragon -a ..\tools\AVRDragon\dragon_fw.zip

All done – the AVRDRAGON should be working normally again.

Categories
General

IFTTT automation using crontab on Debian / Raspberry Pi

We were planning an extended vacation and had concerns about leaving the house empty for so long. As usual you get family and friends to look in every so often but I decided that it would be nice to have some additional security to make the house look occupied.

After a bit of research I decided on Internet Enable D-Link DCS-5030L Camera and a set of Meross Smart Plugs. The D-LINK camera was position in such a way that the door could be monitored while the Meross Smart Plugs were connected to various lights strategically placed around the home.

I setup everything up and it all worked perfectly using the Mobile Apps that I installed onto my Motorola Moto G6 Play. It took a weekend away to realise the problem with this setup – If your mobile was not connected to the mobile network or a WIFI signal then all the automation provided by the Apps became worthless.

The D-LINK camera had a simple solution in that it had its own built in webserver. This meant that I could browse to the camera on my home network where I discovered some settings that would cause it to send a series of photo by email. These photos covered three seconds before and three seconds after any detected movement – which was perfect for monitoring anything dropping through the letterbox.

The Meross SmartPlugs had no such interface and it turned out that the Phone App was all that was controlling them. If you were out of coverage the moment a switch on/off event was scheduled then that event was missed causing either the lights to stay on or off until the next event.

As it happens the Meross Plugs stated that they were compatible with IFTTT so I decided to see if that could help the situation. It was straightforward to get IFTTT to control the plugs and so the problems was solved, or so I though… until I realised that IFTTT needed some external trigger and suddenly I was back to square one :- The phone could be out of coverage and thus unable to control the plugs using IFTTT.

It quickly became apparent that I would need some programmable server attached to my home broadband connection to control IFTTT autonomously. As I had an old unused Raspberry Pi (1st gen) I decided to see if there was anyway it could be used to control the switches via IFTTT.

IFTTT has a facility whereby the item (in my case plugs) can be controlled by posting a trigger event to the IFTTT server. I installed curl onto my Raspberry Pi:-

  • sudo apt update
  • sudo apt install curl

Curl allowed me to send a POST message to IFTTT directly from the command line:-

  • curl -X POST https://maker.ifttt.com/trigger/lights_on/with/key/{KEY}

Obviously “lights_on” and {KEY} would need to be updated with values that have been provided by IFTTT for your own application.

The next step was to get the Raspberry Pi to send those messages at the appropriate time. Fortunatly the Raspberry Pi runs Linux which has a featured called the crontab. The crontab allows you to schedule commands to be executed at specific times and dates.

# m h  dom mon dow   command
 36 17 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/kitchen_on/with/key/{KEY}
 57 18 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/kitchen_off/with/key/{KEY}
 58 18 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/study_on/with/key/{KEY}
 24 19 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/study_off/with/key/{KEY}
 25 19 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/lounge_on/with/key/{KEY}
 30 21 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/kitchen_on/with/key/{KEY}
 36 21 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/kitchen_off/with/key/{KEY}
 36 21 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/lounge_off/with/key/{KEY}
 37 21 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/study_on/with/key/{KEY}
 17 23 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/bedroom_on/with/key/{KEY}
 25 23 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/study_off/with/key/{KEY}
 19 00 * * * curl -X POST -X POST https://maker.ifttt.com/trigger/bedroom_off/with/key/{KEY}

The first five columns in a crontab are used to indicate:- Minute past the hour, Hour in the day, Day of Month, Month and Day in Week. A ‘*’ character in any field means don’t care. Anything after the fifth column is regarded as the command that will be executed.

If you leave open a ssh port on the Raspberry Pi and configure your home router to forward any ssh connections to the Raspberry Pi then it will be possible to login and modify the schedule while away.

In my case this setup worked perfectly for the first five weeks and then everything stopped responding. I suspected the router had gone down so asked a family member to reset it. It turned out that a small water leak from the upstairs bathroom had come through the ceiling and soaked the router.

“But Mousie, thou art no thy-lane,
In proving foresight may be vain:
The best laid schemes o’ Mice an’ Men
          Gang aft agley,
An’ lea’e us nought but grief an’ pain,
          For promis’d joy”

from “To a Mouse” by Robert Burns

Categories
General Qt

Installing Qt on Debian Linux

Before installing Qt on Debian Linux there are a few pre-requisite packages that must be installed.

  • sudo apt update
  • sudo apt install build-essential
  • sudo apt install clang
  • sudo apt install libgl1-mesa-dev

Now that these packages have been installed you are free to Download Qt and extract it into a directory of your choosing.