Electric Bikes – odometer

7th February 2017 – 7631 kilometres

4th November 2016 – 7432 kilometres

18th October 2016 – 7245 kilometres

5th October 2016 – 7080 kilometres

20th September 2016 – 6910 kilometres

7th September 2016 – 6803 kilometres

22nd August 2016 – 6703 kilometres

12th August 2016 – 6610 kilometres

5th August 2016 – 6553 kilometres

22nd July 2016 – 6389 kilometres since June 2014

Posted in Electric Bikes

Anatomy of a scam

This post may take a few days, so keep coming back!

Some background first. I repair computers, and a few customers (3 or 4) have been hit by the “Windows Corporation” scam, where someone thief rings up with a very Indian accent, but with a very English name, claiming to be from the Windows Corporation, or Microsoft, and tells the victim that their PC has been infected with malware and is busy infecting others and other bad things. Most people are not taken in by this but some customers get confused, maybe they have just seen an adware or malware message on their PC, or have just changed email addresses, or are not well at the time, and they are taken in to some extent. Most don’t actually pay these thieves any money, claiming to not have a credit card and are housebound etc. But by the time they get to this stage, the damage has been done. Next time they log on, the system asks for a Startup Password, which they of course don’t know. Soon after they get the second call from the thieves telling them what has happened and how much they have to pay. Fortunately for some, they call me rather than pay the thieves. I have a couple of effective solutions to unlocking the ransomed PCs in this case, and it normally takes just 30 minutes to undo the damage.

Strangely, I am also on every single list there is for these people, and I get several phone calls a week from similar callers. Because my home phone is forwarded to my cellphone, I can ignore them most of the time, but occasionally I get to the home phone in time and field the call. At first I called them names, or led them on and then told them they were stupid and hung up, but more recently I have decided to find out more about the scam and have been actively using the calls to get more information. It takes a good 30 minutes of my time, but some days I can spare it! To this end I have a “disposable” PC set up with nothing on it, which has no access to the rest of my network.

So, how do these calls go?

The opening blurb is much the same, introduces themselves with an English name (Jack Dawson was the latest, and the technician was Will Harris or something similar). They tell me that my PC has been monitored and has malware infections and has been doing all sorts of things, all of which  are bad. This is designed to scare and confuse.

I am told to get to a PC and switch it on, and pestered until I say it is on. In the meantime, they are asking questions about who uses the computer, how old it is, and whether I use it for secure applications, such as banking, shopping etc.

When the computer is going, they ask which key is at the bottom left of the keyboard, and then which key is next to it. They are obviously finding out if the keyboard has a windows key, but depending on the answers could be gauging the level of knowledge of the victim.

When answering these questions I have been a bit silly in the past, if I want to trap these people better, I need to pretend I know nothing about computers, but that I do internet banking with three banks, manage my stock portfolio and keep my bitcoin wallet on there!

Any way, once they know the keyboard layout, the fear and confusion continues. I am told to press the Windows key and hold it, then press the “r” key, and am asked what I see on the screen now. What you see of course is the run dialog box, and I am then asked whether the box on it is empty.

The thief then asks you to type in, one letter at a time (e for elephant, v for victor, e for elephant again etc) the word “eventvrw’, and as with all steps below, I am asked what I see now.

From here I am told to click on Custom Views in the left pane, then Administrative Events in the middle pane, and am asked what I see, which of course is red exclamation marks and yellow warning triangles with hundreds of errors. When I admit I don’t know what these are, they are described in gory detail as errors caused by all the bad software on my PC, and how only they can fix it. This spiel can take many minutes!

So having agreed that this is very bad and should be fixed, the thief offers to fix them for me. OK says I, let’s do it!

So, Windows R again, and www.1234computer.com in the white box. I have complained to the powers that be about this website, so it may be something different when you get your call! Of course this starts up a web browser with a quite sophisticated web page on it, very little of which actually works. At the bottom of the page are four flashing buttons labelled Server One, Two, Three and Four. Clicking on Server One starts a download of Teamviewer. All this is done while comforting words about how normal all this is and how it will help get rid of the malware.

Teamviewer is a legitimate application, which is used to give people you trust access to your computer, so that they can fix errors on it etc. Some computer technicians use this a lot rather than travel to customers sites. Personally, I like the personal interaction occasionally. However, when thieves and scoundrels get access to it, they can do so much bad stuff to your PC.

The other three buttons are links to alternatives to Teamviewer, like Supremo, ShowMyPc and AnyDesk. Other web pages such as AMMY.COM carry the same links.

So OK and download are clicked as requested, and TeamViewer downloads, installs and runs for the first time all with no further intervention. After describing what I see, it is explained that I am going to give their technician access to my computer.

This is the clever bit, I thought they would ask for the partner ID and password that is shown on the left of the TeamViewer screen, but what they actually do is give the victim the Partner ID and password generated on their technicians PC by team viewer. Now this would normally give me control of their computer, but a menu appears at the top of the screen, and I have to select/click the “Switch sides” button, which then gives them access to my desktop. At this point I am handed over to a technician on the phone.

The technician starts by repeating the eventvrw demonstration, adding the technical confusion to what the first guy said. He then uses Windows R and types in “inf”. This displays the contents of the /windows/system32/inf directory, which I never seen before. He then asks if I recognize any of these folders and files, to which I answer, honestly for the first time, “No”. Finally, he gets up a list of services, and explains that some of these services are stopped. Yes, I agreed. He then asks me to scroll down and see how many there are. I declined, saying I believed him, but then he came over all “school teacher”ish, and insisted I scroll down through the list and counted them one by one out loud! I gave him a not so small piece of my mind about what I thought he could do with that idea, which he accepted and moved on from.

Now, while continuing to talk about malware, stopped services etc. once again I saw the run dialog appear, and the word syskey typed in. Syskey would normally allow him to encrypt a very important part of the file system, and add a password to the encryption so that the computer will not start without the password. Unfortunately for him, I recently upgraded this PC to the very latest version of Windows 10 – the Fall Creators update, aka 1709. 1709 has many improvements, but an interesting one is that SYSKEY no longer works on this version of windows! I watched him try a few more times in obvious confusion.

In the meantime, the voice changed again, and I started to get the hard sell, that they would repair and maintain my PC for a payment of just $400 odd dollars, and how would I like to pay. I was going to go through the process and pull out at the last minute of give false credit card details when I realised I would be wasting my time, because they had no leverage over me (they could not hold my computer to ransom) they would just give up and not ring back. So I switched off the router and hung up before they got malicious and started deleting files etc.

So the anatomy of a scam is not complete, I need to take it to the point where they think they can ransom my PC, i.e where SYSKEY was successful.

I have two options, firstly I just finished building a Windows 7 Pro pc up from a cast off by a local business, and I could sacrifice that, allowing them to really use SYSKEY and lock it up. I would have no problems unlocking it.

Secondly and much more fun, I have developed a Windows application that exactly mimics the windows and navigation flow of the SYSKEY application. This took a few hours of development, it is just two screens and a couple of message dialogs, with radio buttons and buttons to navigate by. The main difference is that instead of encrypting the SAM hive file and adding a start up password, it just records the password on a text file. There is no real indication that it is not the real thing.

This program has been compiled into an .exe file, and it is just placed into the c:/windows/system32 folder, and it will run just like the real thing. Download a copy of the fake syskey in zip format here. Of course you could use this to replace the real syskey on any computer, just back up the original and replace it with the fake. You will need a folder c:\secret to store the password file in, otherwise the program will fail with a suspicious error message. Test it before you use it for real, to make sure it is allowed to run by windows, but set the password to spaces before letting a scammer loose on your PC.

This program displays the password if you need to demonstrate it to a scammer, all in the spirit of good fun of course. I leave it on the desktop, if no password exists it doesn’t do much, if one does exist it shows it.

So now I am just waiting for the next call!

I watched a video recently about scam baiting (one of thousands out there), and I am pretty certain it was the same guy as I dealt with, same script delivered in the same way, same web site, and the same method of using Teamviewer. The scambaiter didn’t click on the switch sides button, instead he clicked on actions/disable remote input, then attempted a syskey on the scammer. The scammer was immediately suspicious and disconnected the connection to his computer pretty quickly (I would switch the router off – by far the quickest option). I just tried it on my workshop machines, and if you worked really quickly you might just get away with it, the trick is to say the right things while you are doing it, the scammer can’t see what you are doing, but neither can he move his mouse or use his keyboard. Maybe something along the lines of “Hey, my Teamviewer has locked up, how about yours?”. Maybe I will try that in subsequent calls, or maybe after they have attempted a syskey on me!

Posted in Computer Stuff, Windows 10

Onion Omega – next steps

I have made some serious changes to the PHP web page which servers up the door controls and web cam images, so I decided to finally get FTP access to the files on the Omega. The arrival of my second Omega made this even more relevant!

Wirelessly access and edit the files on your Omega using the SFTP protocol

1. setup the Omega to accept incoming SFTP connection requests. To start, edit /etc/opkg/distfeeds.conf, and find the line below:

## src/gz reboot_packages http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/packages

Remove the two # signs and the whitespace at the beginning so it looks like this:

src/gz reboot_packages http://downloads.lede-project.org/snapshots/packages/mipsel_24kc/packages

2. Ensure your Omega is connected to your WiFi network, then connect to the command line and run the following commands:

opkg update
opkg install openssh-sftp-server

3. Reboot the Onion Omega just to make sure.

4. Start your chosen FTP client (since FireFTP stopped working, I have moved back to FileZilla), and set up the IP address (either Omega-xxxx.local,  192.168.3.1 or your permanent IP address on your network, set up the user name and pssword, and the port 22.

With this set up properly, I am now able to keep backups of my php and python files on my PC, and edit them using Notepad++. The console on the Omega is a bit too flakey to use reliably, and nano on the putty terminal was starting to get tiring!

I also received another Omega2+ and a Mini Dock a couple of days ago, and I am using it to replace a Raspberry Pi I am using to run a second web cam which I use to view the driveway outside my new solid garage doors!

You would thing a simple thing like this, which is just a subset of the previous Omega setup would be relatively easy by now, but it seems that nothing is easy with an Omega. I thought I must have done something pretty serious to my last one during set up, as eventually I had to restore to factory settings using a USB stick with the latest Mega operating system on it. But no, I carefully went through my setup as detailed below, and when I set up the fixed IP address my modifying the network config file, suddenlt I lsot my wifi connection through the internet, and no amount of reverting, copying from other devices etc could get it working again. I tried many times and methods to revert to factory settings, pressing the reset button for 10 seconds, logging on and using command line stuff, connecting serially. I eventually got to the point where I was trying to reset to factory using the USB stick, but this failed repeatedly also, despite working fine on the last Omega.

Eventually something happened (sorry can’t be more specific – I don’t think I did anything, except possibly leaving it alone for a couple of hours) and it went back to factory and allowed me to set it up from scratch. As per the first time through, and the previous Omega, things like the Editor did not work properly, and still doesn’t. The only thing I am getting is an error message about corrupted Time Zone databases when I try to use the date functions in PHP.

Anyway the steps I took are:-

  1. Set up out of the box, connecting to my home network.
  2. Change passwords for root and AP wifi access. Set up timezone.
  3. Logon using Putty to omega-xxxx.local.
  4. Install Nano
  5. Edit the /etc/config/network file to set up a fixed IP address
  6. Install PHP
  7. Install MJPG-Streamer and set up new camera by editing /etc/config/mjpg-streamer
  8. Set up access for SFTP client (see top of this post) and set up Filezilla.
  9. Modify and upload an index.php file that allows me to view the attached web cam, and also the webcam attached to the first omega.
  10. set up JuiceSSH on my phone to allow me to edit files etc from my armchair!
  11. Finally, in order to get the camera out of the way and out of the sun, I mounted it at the top of the window rather than the bottom, which meant it was mounted upside down. Unfortunately MJPG-Streamerdoes not appear to have the option to rotate the image, so I had to modify the pages that stream this webcam to rotate the image.  This page has a good write up and CSS code to do it.

The secondhand Logitech VUCR45 webcam I picked up from our local cash converters for $12 is great, it has exposure control, so it doesn’t burn out the image at midday, and in the evening the street lamp allows some visibility on the road and driveway. Much better than the old DSE camera I was using before.

Both omegas are a little slow when either or both webcams are in use, sometimes they are prettty much in sync, other times they can lag by seconds. More work is needed in this area.

 

Posted in Computer Stuff, Onion Omega - Internet of Things

Business Directories – unsolicited entries

I seem to be getting a number of requests by phone and email to confirm details for an entry on yet another internet business directory.

I fell for this as the start, adding myself to a couple of directories, at the time they were respectable and small business advisers advised “claiming” your listing. Since then, they have continued to nag me to upgrade, pay for better listings, look at my viewing figures (which are usually zero). I feel sorry for the people who work for these organisations, so I quietly ignore them.

However it is now getting ridiculous, every man and his extraterrestrial alien (the last one I dealt with was called Kang – I kid you not) thinks that they can set up a business search directory by stealing entries from other directories, asking you to claim you entry, and then asking you to buy a better entry the colour of some precious metal, with a similar cost!

These entries are inevitably wrong, having been filched from another incorrect, out of date directory. In order to correct them you have to claim them and then change the details. What you end up with is a mass of incorrect entries on little used business directories, or with dozens of directory entries to remember logins and passwords for, to maintain details for, and pay for if you are daft enough to be taken in. Fortunately, I have never, ever received any enquiries from customers through any of these directories, so I don’t worry too much either way.

Then there are the cold callers claiming to be from some directory or other asking “can we just confirm your email address/postal address”. When I have clarified who they are, I mention that I don’t remember requesting and entry in their directory, and they ring off pretty quick. I suspect some other sort of scam, but I would have to confirm the details to get any further into the conversation, which I am not prepared to do.

With the latest email attempt, I have decided to see if I can get the entry removed, as I didn’t request it. So I used the Help button, which brought up a page where I could ask a question of the company. The form was prepopulated with my email address and name, so I assumed they would know who I was  when I asked how I could get the entry removed. I then received an email, asking me for my email address and my company name! I have just received another email telling me the entry has been removed. I shall check later.

Posted in Computer Stuff, Uncategorized

Yuba – display woes

After just a couple of hundred kilometres, the main display unit described below stopped working correctly. It bega with it occasionally not switching on first time, needing a repeat try, and this gradually got worse until it was taking 6 or 7 tries to get it switched on. Eventually it reached the point where it would just not start most of the time. In amongst this, occasionally it would start with psychedelic patterns on the screen multi coloured bars and stripes flickering, and only a full power down would fix it.
I checked the switch unit (which is just that inside – no electronics). I used a multimeter across the contacts, all was good.
Contacted the supplier, PSPower, who wanted me to pay postage back to china, lie about the worth of the device, pay any tax they were changed by customs, and pay a US$20 postage and packaging to have it returned. For this they would send it to the factory to have it repaired. I have never been really happy with PSPower’s service, even when they were E-Life Bikes, so may not be using them again.
Fortunately the display that came with the Leckie kit still works fine, so am going with slightly less bling and features for now!
Shame, I really liked that display!

Posted in Electric Bikes, Yuba Mundo eV4

Garage Door Opener – a tinier computer project

Despite the issues with bricking the device and it recovering itself in a random state, I decided to go with what I had rather than risk bricking it again. This caused a few issues, but I can live with them. Below are the steps and some notes about how things went.In the picture below is the complete Raspberry Pi installation, below it the compete Omega installation.

Omega v Pi

Omega v Pi

Set up steps

  1. Unbox and plug in. Lovely packaging, shame to take it out really! I used a stanndard Micro USB cable plugged in to an office PC with a wifi connection. You have to use another computer with a wifi connection,
  2. Connect the computer you are using to the new wifi network that has appeared in your list, in my case it was called Omega-48CD. The 48CD part is the last 4 characters of the MAC address. The default password is 12345678. The Omega is acting as an access point (AP).
  3. Use a browser to log on to http://omega-48cd.local. The Omega set up wizard will start, and you can go through the set up process – login, wifi, update software, install console and latest firwmare updates.
  4. When Omega is rebooted, use a browser to go to http://omega-48cd.local again and log in to  console using “root” and “onioneer”. In general settings, change the password for “root”, change access point password, check for firmware upgrade again.
  5. In order to install all the software I required to create the Garage Door opener, I was probably going to need more than 32MB of storage. I bought the Omega 2+ because it had a built in Micro SD card slot, which can be used to extend the onboard storage.
    I have a 4GB Micro SD card which seemed ideal, so I put it into the Omega 2+, and changed system to boot from it. Full details can be found here on the Onion Omega 2 Documentation pages Make sure you follow the instructions exactly, especially when changing the config file, a mistake in the overlay line just stops it working.
  6. I am a PHP programmer, not a python programmer, so I want to use PHP to process my web pages. In fact, I intended to use exactly the same code as I used on the PI wherever I could. I needed to install PHP as detailed in the documentation pages. I don’t need to install a web server, as the Omega comes with its own light weght one installed.
  7. I like to use Nano (OK I dislike using Vi or Vim – I haven’t had a pony tail for many years now) so I installed the Nano text editor using
    opkg update
    opkg install nano
  8. Much as I want to use PHP, somethings have to be done in Python or C. I dislike C more than Python, so I used this page to install python light. No need for the full version, the sole use is for the relay expansion.
  9. In order to control the relays on the relay board, I needed to install the relay expansion python module. This is a Python script which may use a C program, and it delivers functions to initiate the relays, and to set them on and off. These can be called in small python scripts I have to write, which in turn will be called from my PHP code.
  10. change ip address to static by editing /etc/config/network with (my settings  – use your own based on your router). The last line seems quite important, I didn’t need it on the PI changes, but the Omega won’t work without it.
    config interface 'wwan'
    option proto 'static'
    option hostname 'Omega-48CD'
    option ipaddr '192.168.1.99'
    option netmask '255.255.255.0'
    option gateway '192.168.1.254'
    option dns '8.8.8.8'

    And maybe restart the network using /etc/init.d/network restart and the DNS thingy using /etc/init.d/dnsmasq restart
  11. The Omega is set up to use webcams virtually out of the box using the MJPG Streamer package. This a little basic, but seems to work very well. Just plug in the camera and set up config file. I used a Logitech C525 or similar (looks a lot like one) that a customer recycled through my business. The Omega can handle really high quality video, so I set it to its proper resolution (1280 by 720) with a frame rate of 30 and quality of 80%. This is done in /etc/config/mjpg-streamer. The camera can be tested in the console, and from that test you can get the code needed to stream the camera in the web page. In my case it was
    <img src= "http://192.168.1.99:8080/?action=stream"/>

    where 192.168.1.99 is the fixed IP address set up above, and 8080 is the port allocated in the /etc/config/mjpg-streamer.
    I had an issue with starting the streamer, this code automatically starts the streamer at start up. /etc/init.d/mjpg-streamer enable
    Full details of streaming over wifi are here
    The camera and the Omega work really well together, and seem to cope with low light a lot better.
  12. Set up python scripts to flick relays on and off. These are based on the routines I set up for use on the PI, but the functions called are a little different. The lines in red check to see if the relays are initialised, and if they aren’t, initialises them The code in blue sets the channel zero relay on, then 0.2 seconds later, sets it off.
    The addr value of 7 is the hardware address of the relay board. If I added more relay boards, each would need a different address. A similar script does the same for the channel one relay.

    '''**************************************************************************** $
    Pulse relay number 1 for 0.2 seconds
    By dave Glover
    www.signsofsuccess.co.nz
    ******************************************************************************* $
    from OmegaExpansion import relayExp
    import sys
    import time
    addr = 7
    relayExp.setVerbosity(0)
    ret = relayExp.checkInit(addr)
    if (ret != 1):

    ret = relayExp.driverInit(addr)

    print "checking if initialized: ", ret
    ret = relayExp.setChannel(addr, 0, 1)
    time.sleep(.2)

    ret = relayExp.setChannel(addr, 0, 0)
  13. As mentioned above, I used the PHP script to generate the web page that I created for the Raspberry Pi version, This needed very little modification. Below is the PHP portion of the code, with the changed lines highlighted. Executing the Python scripts in PHP is much easier, no need to use Sudo, and no need to give the PHP program god rights to use Sudo without a password! The video live stream is discussed above.
     <?php
     if(isset($_GET['n'])){
     exec('python /www/omegarelay/relay_flick_1.py');
     echo '<div class="notification">North door activated</div>';
     }
     else if(isset($_GET['s'])){
     exec('python /www/omegarelay/relay_flick_2.py');
     echo '<div class="notification">South door activated</div>';
     }
     if(isset($_GET['vo'])){
     echo '<div class="notification">Waiting for input</div>';
     }
     else {
     echo '<div class="notification">Live video stream</div>';
     echo '<img src= "http://192.168.1.99:8080/?action=stream"/>';
     }
     ?>
  14. With it all set and tested on the bench, the Omega was attached to a 4 pin socket for the relay connection, a wifi antenna was attached just to make sure, and the camera on the ceiling was changed to the new Logitech camera, and connected to the Omega. Power was applied, and the new Omega garage door opener was up and running.A step by step, feature by feature comparison with the Raspberry PI will follow. First impressions are that they are fairly evenly matched, with specific difficulties and features in each device.

Screen shot with new camera on Omega 2+

Posted in Computer Stuff, Onion Omega - Internet of Things, Programming, Raspberry Pi

Garage Door opener – intermission

The last post about Garage Door openers detailed the building of the garage door opener, but blurs the time line of events a bit.

Initially I got the opener working fine, and it worked well for a few days, but was a little flakey – nothing you could detail, it just reacted strangely at times, taking its time to load or start. This got worse until after a few days it became a bit useless. Attempted repairs and some investigation did two things – firstly it just stopped working – white screen web page when browsed to and secondly that the images and videos saved by the motion software had completely filled the SD card. Deleting the images and re-installing various bits of software made no difference.

So I initialised the SD card, downloaded and installed a new version of Rasbian Stretch Lite and started from scratch building the garage door opener again. During the process I discovered the motion settings that turn off the saving of images and videos – the images and videos are pretty poor quality anyway, neither the camera or the Pi is up to producing high quality. In the future I may well record images and videos, and set up a cron job to delete anything older than a day or so, but in the meantime the system runs without clogging up the system with images.

Second time round it still took about 3 hours to set up the whole system, but the result is much better. It has been up and running now for at least a week non stop. It responds quickly, and the live video feed is just 1 second behind real life. The camera is useless in low light, so a better camera or possibly a relay controlled light is required in the future.

In other news – the Onion Omega 2+ IoT device arrived. Much more on this later, but I spent a few hours on Monday evening going through the set up process, and decided I wanted to add a micro SD card to extend the file system to 4GB for later installation of PHP, Python etc. I went through a process which proceeded to almost make the Omega unusable – the name change from Omega-48CD to Omega-000, which is a sure sgn of it being bricked. I fiddled for a while, and eventually it came right. I then decided to revert it to factory settings, when it promptly did the same thing, and no amount of fiddling would get it back. So it appeared to be bricked. I did the 10 second hold of the reset button which had no effect. I noticed the processor was running hot, so I gave up for the night. Today (Thursday) I plugged it it again, and lo and behold, everything back to working. Passwords, wifi etc were all reverted back to factory settings, but the software was still the very latest updates.

So I have a working Onion Omega 2+, I have a working prototype Garage door opener on a Raspberry Pi, time to start building the real thing!

Posted in Computer Stuff, Onion Omega - Internet of Things, Raspberry Pi

Garage door opener – tiny computer project

Recently we had two new garage doors installed, to replace very old clunky things. The new doors are sectional, insulated and have brand new automatic openers. They are draft free and the temperature in the workshop is a few degrees higher, and the noise level is a lot lower.

With the doors came 4 key ring wireless remotes, and two wireless wall mounted remotes, one of which is mounted between the two doors, and the other is mounted by the connecting door between the garage and the main part of the house. When we bought the doors we considered getting either an external keypad entry, or a wifi base system that used an app on a mobile phone, but the extra cost put us off a bit. Under the covers of the door openers is a connector block, and a connection labelled OSC or O/S/C can be used to connect a momentary switch to control the doors manually, but this is not used in the installation, all controls being wirelessly attached.

Since then I have started to get irritated always having to carry one of the wireless remotes, they are small, but still a nuisance on a key ring, and I am always misplacing or forgetting to carry them. In  particular when I am working in the garden, when I want to use the garage without walking through the house in dirty boots. So I am revisiting the idea of a wifi based door opener, using my phone as the remote. Thing is, I am a user of Arduino, and Raspberry PIs, and have a couple of each lying around, and was pretty certain I could do something myself, and learn something about IoT (internet of things) at the same time.

The obvious place to start is on the internet, and searches found quite a few projects out there, each with their own good ideas and quirkiness. The most interesting of which seemed to be based on relatively new technology called the Onion Omega 2. This is an IoT specialist product. Barely larger than a large postage stamp, this device is reasonably capable Linux based computer (preloaded with linux), with built in wifi, GPIO pins and a bunch of other cool stuff, including very low power consumption. The main board requires an expansion board to be really useful (i.e. to give it a USB port, power supply switches, leds etc),  so the $7-$9 price goes up by another $15, and to control the doors I figured out I would require a relay board, which is available for another $15, and comes with two relays (one for each door).  This relay would be attached to the door openers, at the OSC and zero volts connectors.

So on the promise that I can program in PHP, not just Python or similar, I ordered the necessary bits, and in two or three weeks the courier will knock and I will take possession!

Until then, I thought I would prototype it with a Raspberry PI. Not quite as small, a bit more power hungry, but still a Linux based computer, with USB, power supplies, GPIO pins etc. No wifi built in on my version, but wifi dongles are fairly cheap. I have a spare Raspberry Pi 2 Model B in my box of bits, with a 4GB SD card loaded with Rasbian. Time to get started.

It booted up fine, but previous incarnations of this computer were still on it, namely a display of business related photos that started automatically at start up. I could not for the life of me remember how I did this, as it was at least 4 years ago, so I decided it was time to upgrade my version of Rasbian. A quick visit to the Rasbian download page and I was downloading the latest version, and using the suggested image burner to update my SD card. Except – my 4GB SD guard was no longer big enough! Linux bloat is even affecting tiny computers. Back to the download page and there sitting next to it was a “Lite” version, which does not have the desktop software included. As this computer is to run headless (no monitor, keyboard or mouse) I decided to bite the bullet and go for this version – it will save me the cost of a new Sd card! Downloaded, installed and plugged into the Pi, it was time to start the setup.

To get through the initial steps, I plugged in a mouse and keyboard, and an HDMI monitor. A number of set up changes and software installs are required, including.

  • Change the password to log on to the machine. Use sudo raspi-config.
  • Setting up the date and time zone, and allowing the whole of the SD card to be used as system memory. Use sudo raspi-config.
  • Allowing another computer to SSH into the computer. Use raspi-config again, as described here
  • Installing and enabling an FTP server, Proftpd was the one I used, description here.
  • Installing Apache and PHP, this page is useful
  • Installing the Motion software for the webcam, and allowing the webcam to be used on the local network. Useful webpage here and use sudo nano /etc/motion/motion.conf to change the camera setup as required.
  • Install the software for getting access to the GPIO pins. As I am now using a Raspberry Pi Relay Board, which uses I²C instead of GPIO pins, this has become a bit redundant, but details are here.
  • Some extra work around the SMBUS and I2C tools is required for the Relay hat, this page here will help.
  • Use  sudo visudo to modify  /etc/sudoers.  An extra line is appended to the end of the file, namely www-data ALL=(ALL) NOPASSWD:ALL. Beware - danger!
  • Installing and setting up the wifi dongle (an Edimax Nano type). Instructions here.
  • Setting up a fixed IP address for wlan0 while you are installing the wifi dongle, especially if your router won’t let you reserve IP addresses.
  • Set up a cron job to remove the days image files, useful page here. 
  • Or, instead of a cron job, update the /etc/motion/motion.conf values to switch off recording the images.

There were myriad other little things I had to do, which I didn’t write down or remember. Once I had an IP address for the PI on the local network 192.168.1.73, I was able to use PuTTY to login to the new machine, and set up an FTP client to look at /var/www – I needed to change the permissions on this directory to get full access to to it. This meant I could remove the HDMI cable, mouse and keyboard, and the ethernet cable.

All this took a few hours of trial and error and finding out what I needed and how to install it, set it up and use it on the web.

At some point I created a “Hello World” PHP web page, and used a browser to look at the new IPaddress 192.168.1.73, which gave me the standard Apache opening page – index.html. As I wanted to get to index.php I wondered if I had to set up the Apache to look at this page, but I just had to remove the index.html page  from /var/www/html and the .php page was picked up and processed properly.

I added a form with a couple of Submit buttons and played with formats and actions, finally connecting the GPIO pins 17 and 27 to LEDs, and was able to turn LEDs on and off using the webpage on my phone or desktop. As the relays are going to simulate a momentary press, the buttons flashed the LEDs for just a second. I don’t have any relays currently, so this is as far as I can go down this path. I have orderd a Raspberry PI hat with 4 relays on from Nicegear, a NZ supplier, and this should arrive in a day or two and I can go on to the next phase of testing.

However, I don’t want to open and close the doors without making sure there is nothing in the way of the doors. If I am standing outside them with my phone, this is not an issue. If I am sitting upstairs wondering if the doors are shut or not it would be nice to know if they are open, and if the car or bike is parked halfway in! There are many sensors you can add  with safety beams, magnetic sensors etc, but I decided to add a webcam inside the garage allowing me to see the state of both doors.

When I downloaded and installed the Motion software to manage the web cam, it set up the camera on port 8081, and I made a couple of other changes to optimise for the rather slow R-PI and the rather rubbish web cam I found lying on my bits box. It turns out putting the camera onto the web page is as simple as

<img src= "http://192.168.1.73:8081/?action=stream" width="320" height="240"/>

The R-Pi is operating as a web server, serving up a simple web page direct to the  local IP address. It cannot be accessed outside the local network. The PHP program receives the input from a few buttons on the web page, and changes the state of a couple of GPIO pins, which flicks relays on and off, replicating a button press on the garage door opener.

By default the motion software records images when motion is detected, and records a video  until motion stops. This can quickly fill up an SD card. Use the following settings in the /etc/motion/motion.conf to get it all working properly. Framerates and image size may depend on your camera.

output_pictures off (default on)
ffmpeg_output_movies off (default on)
stream_localhost off
daemon on
stream_maxrate 10
framerate 10
weight 320
height 240

As the garage is dark most of the time, I may add a light which will be controlled by one of the spare relays on the PI Hat in order to see what is happening with the video camera.

OK, the relay hat for the PI has arrive, and I spent the first few hours staring at it wondering what I had bought! This is what I bought, a Seeed Studios Raspberry Pi Relay Board V1.0. Looks great, but it took me by surprise. I figured it would work by just setting GPIO pins on and off, on the basis it is plugged into the GPIO pins on the R-Pi. Instead, it uses I²C to connect from chip to chip, and the only pins it uses are the power and ground, and the two oins used for I²C. What this means is that there us a serious lack of information on how to use it. There is a WIKI entry on the page, which is a variation on this original page by John M. Wargo. The information here is not for the novice, and all the code is in Python, which I have little knowledge or experience of. Hours of fruitless searching resulted in no further ideas in how to use it in my PHP pages. I did however look at using Python Scripts in PHP scripts, and it didn’t look too hard.

So, I worked my way through Mr. Wargo’s page, installing and testing the card using a terminal to run the test scripts to test it all worked. I had  couple of things to install/change around the use of SMBus, this page here helped a lot. Eventually satisfying clicks were heard from the relays when the scripts were run from the terminal session.

The next job was to get scripts working in my PHP page. The concept is quite simple, use “exec (python /path/to/scriptname.py)”. In reality it is a little trickier. While the Python scripts run without root permissions in the terminal, to run them from php we need to use “exec (sudo python /path/to/scriptname.py)” . This throws up the issue of Sudo requiring a password to run. There is much about this, and the most common solution comes with dire warnings about using it.

It involves The reason this is so dangerous it that it means the apache user www-data has root permissions without requiring a password, which open up the Pi to all sorts of hacking. If this is important to you,don’t do it. If you do do, use visudo to edit the /etc/sudoers file, as it validates what you are changing. Getting back from a corrupted sudoers file is a pain.

Eventually satisfying clicking sounds were heard from the relays while running my test PHP script.  Two new python scripts were written, each hardcoded to switch a specific relay on then off again 0.2 seconds later, simulating a momentary switch. The python scripts look like this and are remarkable simple, making use of the library of functions provided on Mr. Wargo’s page (relay_lib_seeed.py).

#!/usr/bin/python
'''*****************************************************************************************************************
 Switch relay 1 on, wait 0.2 seconds, and switch it off again
 By  Dave Glover
www.signsofsuccess.co.nz
********************************************************************************************************************'''
from __future__ import print_function

import sys
import time

from relay_lib_seeed import *

relay_on(1)
time.sleep(.2)
relay_off(1)

 

The full source for the single piece of PHP code is given below. The red lines are the two critcal ones for calling the python from within PHP. Security is based on this only being available on my home networks, so if you don’t have access to my networks, you can’t see the page.

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Garage Door Control</title>
<style type="text/css">
body {background-color:lightblue;}
h1 {text-align: center; color:blue;}
img {width:100%; height:auto; display: block; margin: 0 auto;}
.inputform {width:100%; margin:auto; }
.buttonline {width:300px; margin:auto;}
.button {height:25px; width:100px; margin:10px 23px 10px 23px; 
 background-color:blue; color:white;}
.notification {margin:auto; text-align:center; color:blue; margin:20px;}
.footer {
width: 100%;
bottom: 10px;
text-align: center;
font-size: 8pt;
}
</style>
</head>

<body>
<div class="inputform">
<h1>Door Controls</h1>
<form method="get" action="index.php">

<div class="buttonline">
 <input class="button" type="submit" value="North" name="n">
 <input class="button" type="submit" value="South" name="s">

</div>
<div class="buttonline">
 <input class="button" type="submit" value="Video On" name="v">
 <input class="button" type="submit" value="Video Off" name="vo">

</div>
</form>

</div>
<?php



if(isset($_GET['n'])){
 exec('sudo /usr/bin/python /var/www/pirelay/relay_flick_1.py');
 echo '<div class="notification">North door activated</div>';
 }
else if(isset($_GET['s'])){
 exec('sudo /usr/bin/python /var/www/pirelay/relay_flick_2.py');
 echo '<div class="notification">South door activated</div>';
 }

if(isset($_GET['vo'])){
 echo '<div class="notification">Waiting for input</div>';
}
else {
 echo '<div class="notification">Live video stream</div>';
 echo '<img src= "http://192.168.1.73:8081/?action=stream"/>';
}
?>
<div id="myfooter" class="footer">
 Copyright Dave Glover (2017<?php if(date('Y') != 2017){echo ' - '.date('Y');}?>)
</div>
</body>
</html>

This is what it looks like

Screen Shot

and it is now installed and waiting for the upgrade to the Onion Omega 2 version!

I made changes to the physical installation, hanging the webcam from a ceiling bracket, so inverting the picture. Back into the camera config using sudo nano /etc/motion/motion.conf and change the Rotate value to 180, and it all looks good again.

Postscript 19/10/2017 – This webcam and garage door opener ran fine for a few days, but started to act badly after a week or so, not responding, SSH stopped working etc. Eventually while investigating what was wrong I got an error message about there being no space on the disk. I an using a 4GB SD card for my system, and it seems that the camera software “Motion” takes still photos and creates videos of everything it sees! This quickly mounts up and eventually the 39,000 images stored on the SD card swamped it! The files live in /var/lib/motion, and using “sudo rm *” is theoretically the way to get rid of them all (after CD /var/lib/motion of course). 39,000 is apparently too many parameters for the command, so I had to break it down into chunks by usin 0*, 1* up to 9* to delete 1/10 of the files at a time. To get round the problem I have added a cron job to remove the files once a day at midnight using “rm /var/lib/motion/*”.

Posted in Computer Stuff, Raspberry Pi

Yuba dashboard upgrade part 2

The new display panel has arrived, and was promptly fitted. Immediate thoughts were that it switched on and worked out of the box! Second thoughts were that the settings were also pretty good out of the box, with the exception of the top speed, which was set to 25kph. This is fine in those  countries with a speed limit, NZ only has a power limit (300w) so I can set the speed limit to anything I like. The number of PAS settings was set to 9, which I have left. One nice feature is that the clock works exactly as it should, and maintains time when switched off or the battery is disconnected, so whatever gave me the idea in the blog below was obviously incorrect.

 

DPC-14/850C on Yuba

The main display unit fits nicely over the handlebar extension, tucked down out of harms way if I have to turn the bike over to work on tyres etc by the side of the road. I rerouted the main loom and associated cables so they run under the handlebars rather than across the top or on the front. A wire runs from the display to the buttons which you can see on the left hand end of the bars.

DPC-14/850C on Yuba

The buttons can fit over the throttle mounting, giving very easy access with the left hand without any significant movement of the hand. Very ergonomic!

DPC-14/850C control buttons

DPC-14/850C on Yuba – set up from front

I downloaded two manuals for the device, one from a USA retailer (Luna cycles , or Empowered Bikes possibly) and one from the manufacturer (Tianjin APT Science and Technology Co. Ltd). They are noticeably different, in that the manufacturer’s version has 4 extra pages, mostly covering a whole bunch of very attractive advanced features, which duplicate some of those in the controller firmware. When I saw these I really got quite excited, thinking I would have lots of options to control the response of the motor to my riding style. Unfortunately, the reality is that when fitted to my BBS01B motor and controller, only the options documented in the retailers version of the manual are available!

Most of the options are to do with display, analogue versus digital, watts or amps, level of brightness. Others are operational, such as number of PAS settings ( 3,5 or 9), wheel size and speed limit. One nice feature is the ability to lock the device, so that a 4 digit PIN has to be entered before the bike can be used. This is a very useful, as it means the bike can be left with the battery switched on, and the system can not be activated. I once had a customer fiddling with my old bike in the shop, who turned on the bike and twisted the throttle to full. Fortunately, it was only 30cms from a wall, so it didn’t go far.

Pressing the up button for a second or more switches from daylight to night settings, pressing the down button in a similar way puts the bike into walk mode. Walk mode appears to work better than it did with the previous controller, which is a bonus. Pressing both the up and down simultaneously resets trip values – trip kms, trip time, average and maximum speeds.

On the road, the display is easy to read, very clear and right smack in the middle! The buttons are easy to get to, and the controls are pretty much the same as the C963 previously used. I haven’t done too much testing of the power delivery,  it is certainly no less comfortable to ride, and the extra PAS settings appear to be useful, they are different enough to warrant having the extra 4 settings.

Is it worth the money? The bike was perfectly usable with the old display, but I like the extra visibility and usability the new device gives, so yes, I think so.

Posted in Electric Bikes, Yuba Mundo eV4

Yuba dashboard upgrade

A few posts below I mentioned that the handlebar display panel was a fairly standard C963 display panel, branded as a Lekkie. It is based on the KM5S made by King-Meter. A quick review of its capabilities compared to what the KM5S manual contains shows that it is quite heavily customised. I am not sure if this is standard Bafang customisation, or whether it is a combination of Bafang and Lekkie requirements, in order to be able to call he motor a 300W motor. Either way, it is not possible to change the PAS settings to 9 from 5, it is not possible to change the top speed on the display panel, and it is not possible to get into the “Personalizes Parameter Setting” section, where there are many more settings of interest. None of this is a real issue, but I do like to tinker occasionally.

C963 Display Panel

C963 Display Panel

One of the main issues for me is the integration of the control buttons into the display panel. This means that I either have the display panel in the middle of the bars, and have to reach over to the panel to change the settings, or I move the display panel so that the buttons can be used while my hand is still on the left hand grip, which puts the display way over to the left, and because of the swept back bars makes it more difficult to read.

So I started to look around for something better. One or two suppliers of Bafang mid drives have started offering a couple of high end display panels, in some cases they are customised, as in the ones by Luna and EMPowered Bikes, and others seem to be as they come out of the factory, from places such as PSWPower and others. There are two models of interest, the DPC-14/750C  and the DPC-14/850C. Both are colour screens, both have separate push button units attached with waterproof connectors to the main unit.  You can look them both up on the internet, they are for sale in many places, on e-bay, Amazon, DHGate and AliExpress , for around the same price give or take $10.

Reading various forum entries, and write ups on websites of retailers, there are some significant differences. The 750C is landscape mode, whereas the 850C is portrait, and the 750C appears to be much more limited in what it can do. They are both direct replacement for the C963 on the BBS02 centre drive from Bafang, and have similar methods of changing parameters etc. Basic operation seems very similar to the C963, so there will be little extra to learn.

So I have taken the plunge and ordered a DPC-14/850C from AliExpress, which is actually being supplied by PSW Power who appear to be a rebranding of ELife Bikes, whom I bought my first ebike kits from! These are not a cheap unit, about NZ$115 delivered, but I am really looking forward to installing it and setting it up to suit how I want my bike to perform.

You can see a couple of its features below, namely a real voltage meter, a power meter as well as all the usual speed, avg speed, top speed, odo, trip options. It also has a clock, but as this does not have a battery, the clock needs resetting before each use. Great if you really need it, otherwise something to ignore. 3, 5 or 9 PAS levels are available via the settings. Bad points – it says Intelligent at the bottom of the main screen! Apparently while this is in firmware, no one knows how to change it yet.

DPC-14/850c display panel

DPC-14/850c display panel

It is in transit as I write, it left Hong King airport a couple of days ago, depending on how many other courier hub airports it goes through, it may be here in two to five days. Better photos and write up when it arrives.

Posted in Electric Bikes, Yuba Mundo eV4

Windows 7 – Windows 10 couldn’t upgrade error

I get this occasionally on computers that weren’t upgraded during the free Windows 10 period. Every time you go into the update screen, the first thing that pops up is an error regarding the Windows 10 upgrade failing. At first I thought this was a recent error, but t seems it is just a hang over from many months ago.

It is annoying, and difficult to find a solution for. This has worked for me a few times.

Open REGEDIT in administrator mode, and navigate to HKLM/software/microsoft/windows/currentversion/windowsupdate/ and delete the OSUPGRADE folder.

At your own risk, back up your registry before doing it etc.

Posted in Computer Stuff, Windows 10