Well first of all happy new year to all! … Today marks the start of a new journey for me, I quit my last job in September last year, I needed a change something new, over the last three months I’ve been gathering all the tools to upcycle old objects, make old new again etc. I’ll hopefully get chance to start incorporating bigger projects in the vblog and you lot will see my mini workshop! Still have a lot of work to do, I’ll write another blog when I have some free time. Once again happy new year and have fun hacking!
I’ve been playing with the openweathermap api thought i’d share a little code, the following pulls the json and constructs a string containing the location, temp, tax temp, min temp and humidity. You will need to sign up for an API key and free user account 1st. The free account at the time of writing this allows 50k calls a day so if you’re writing for a small personal project 50k calls should be fine.
Copy the code below to a file
chmod the file if needed …
sudo chmod +x displayweather.py
run the file using …
r = requests.get('http://api.openweathermap.org/data/2.5/forecast/city?id=YOURCITYIDGOESHERE&APPID=YOURAPIKEYGOESHERE')
data = r.json()
mystring = ""
mystring = mystring + data['city']['name'] + " "
mystring = mystring + "Temp:" + str(int(data['list']['main']['temp'] - 273.15)) + "C "
mystring = mystring + "Max:" + str(int(data['list']['main']['temp_max'] - 273.15)) + "C "
mystring = mystring + "Min:" + str(int(data['list']['main']['temp_min'] - 273.15)) + "C "
mystring = mystring + "Hum:" + str(data['list']['main']['humidity']) + "% "
Well merry crimbo, I hope you had a great day whatever you spent it doing. So i’ve been really busy the last few weeks but I’m starting to have a little more free time now … and thought I’d take this chance to start writing up a little code and project for the digistump.
What is a digistump?
A digistump is a small USB development board that emulates a HID (Human interface device (Usually a keyboard or mouse but there are other variants)). The digistump allows the user to flash up to 6k of code to the device which when plugged in to a computer after programming will execute the code on the device as if it were a keyboard and/or mouse.
Why would I use one?
Its very handy for automating small tasks such as downloading a file and running an install or just editing settings on the pc that remain consistent across operating systems. eg. You could use the digistump to run a command in the command window or run a specific application with certain options automatically. All you need to do is plug the device in after programming and it will start executing the pre-programmed keypresses.
What operating systems does it support?
The digistump is cross-platform this doesnt mean one script works for all operating systems. This means the device is capable of running and executing code on Win/Linux/Mac but due to difference across the various operating systems scripts would need to be customised for each. The digistump has no way of reading data or accepting any feedback from the PC it just blindly presses keys. Your scripts will rely heavily on intelligent timing. Some commands will execute and finish on modern PCs faster than they would on older hardware, this has to be taken in to consideration when writing code.
Where can I get one?
The digistump is available from Digistump.com you can also find them available on ebay and similar sites. I bought mine from ebay for £1.50 each which is a tiny amount when compared to similar devices.
The install procedure is pretty straight forward, download arduino IDE, install drivers and add digistump examples and templates. Which is all detailed on this page here … Getting started with the digistump
The setup is relatively straight forward.
So why am I reading all of this?
Well b/c the digistump is a relatively new product there’s not a lot of reference material on the internet so I started developing a small framework to make it easy to deploy and develop code very quickly. I’ve been busy working on my first little project for the device and right of passage to rick roll any windows 7 users. Although this project is a harmless bit of fun it’s helping me to develop a lot of standardised functions for running applications, opening web pages creating and saving files.
Rickroll notes …
I spent the first few nights tearing my hair out with this device. Here are some of the issues I encountered and how I mitigated them or formed some workarounds.
The first major issue I had was the backslash. The digistump by default outputs US scancodes, as I live in the UK this was an issue. So after much googling and head scratching I figured out that the scancode for the backslash on a UK keyboard was 0x64 yet the digistump was sending 0x31 the US scancode for the backslash.
Whilst I couldn’t figure out where the digistump library resided on the PC I wrote a small function to swap out the 0x31 for 0x64 which seems to have remedied my backslash issues. This is not the correct way to do things.
Eventually I found the library location last night (c:\Users\Username\arduino15\… ). I’m still yet to look through the code and figure out a conversion table for 101(UK en-gb 32) keyboards. Given a little more time I’ll get this fixed and not have to use any functions for string processing.
Another related problem was the saving of files using the %USERPROFILE% environment variable. Full filenames containing this variable were not being parsed properly ie. the environment variable was being read as %USERPROFILE% and not the actual users name. To mitigate this I broke the file string down in to sections and type each part of the save file string in separately. ie. C:\ [ENTER] Users\ [ENTER] %USERPROFILE%\ [ENTER] etc which allowed me to use the %USERPROFILE% variable when saving files.
I’m not going to upload all the code yet as its still messy and I have some functions that need more calling parameters adding so if I released the code now it’ll probably change before the final release and I want everything nice and polished before I release everything.
A great big shout to advancednewbie who’s been working on a special script for the digistump (More on that very soon.) his research and project helped me greatly in trying to figure out the key mappings for most default buttons and some of the UK differences. Given some more time im sure we’ll have this working seamlessly between countries and keyboard layouts.
Even though these issues don’t directly relate to the rickroll project I thought I’d include them just in case anyone else is having similar issues.
Quick blog, had a nice weekend relaxing, I’m going to be busy over the next few weeks starting up a new business so videos, projects and code will be a little thin on the ground. I’ll try my best to keep you up to date with progress and hopefully everything will tie in together nicely. BBS hakologists.
I have my lounge back in order now, have moved the unit to my landing, still not tested but everything is ready to go just waiting for a couple of friends to come and help me move it downstairs. Oh and its Friday so im going to take a few hours off from the hacking spree.
Running on minimal sleep. Waiting for two deliveries at separate addresses on the same day … chaos! Coffee in hand, weather is still terrible. Starting to write up reddit python project notes.
Had a nice early night last night. Woke up spark awake at 5.30 and couldn’t get back to sleep. So decided to make some breakfast have a brew. Loads to do, as you lot may know we’ve had some pretty bad storms in the UK recently and the weather has been particularly crap for this reason I’m avoiding sorting my garage out till it cheers up a little. I’ve got loads of little micro controller projects on the go just trying to condense what I’m learning into some useful videos / code. I’ll probably write up all the notes for the RPi reddit project later on today too with photo’s etc. Right peace BBL
Well hakology need to record a VBLOG later had some new tech arrive, nothing too special, a new microcontroller (the smallest one yet), some adapters and a couple of transistors I need for an RF amplifier I’m looking at building. Need to go and get cleaned up though before I get messy, starting to grow one of those linux admin beards.
Managed to get the arduino mini programmed using another arduino. Having issues trying to get the two boards working in unison the display draws, but I can’t seem to get the time from the RTC.
Up bright and early this morning covered almost head to toe in fibre glass insulation. Rearranging the loft to start putting some temporary flooring up there. Also want to reposition my discone and dig through some of the old tech. I was thinking about trying to pull my old acorn electron down and making a short vblog on it see if I could power it up etc … 1985 vintage … 26 year old capacitors hmmmm ? 🙂
Six hours later and I’ve used all the floor boards I have. Still a long way to go but its a start. Completely knackered going to have a rest and contemplate my next job.
Woke up very late today but respectively I had a very late night last night, tweaking the rpi/reddit/python/arduino project. Im having issues with serial communication somewhere there’s a few bits / bytes being lost? It very irregular and after a little bit of debugging I think its either the serial message get out of sync and missed part of the message or the arduino is rejecting certain characters. The reddit API JSON comes utf-8 encoded and needs converting to ASCII before I send it to the arduino, I’m processing the string to remove and replace irregular characters, I’m going to try changing the baud rate later see if this has an impact.
RE. Wardriving idk if it was where I had the GPS dongle positioned in the car but the GPS co-ords I converted to KML where ALL OVER THE PLACE so maybe its down to kismet and the –use-nmea-gps option this is the only thing I’ve really changed since I last went out. (Regardless of GPS I still managed to get some good data.)
The LED matrix project is looking very slick now, apart from the serial message issues I’m pretty darn happy with it.
Managed to get my keyboard in the post this morning on its way back to the manufacturer for the second time, think I’ve mentioned this before but, really hope they get it right this time (I’ve even requested they send me a different model this time round.) *fingers crossed*
Chores done thinking about doing a vblog assembling a small FM transmitter I purchased from ebay. Will try and get the next main hakology video done first though.
Im only rendering the sdr# video! … still dont have the perfect solution for screen capture but its done now … the audio is terrible near the start next time will record on another device as noise supression appears to be playing hell with my laptop capture, meh, its done now time to move on and not make that mistake in future.
Todays VBLOG I made an FM transmitter from a small kit I purchased on ebay. Just rendering the video and preparing to upload it. This by far was the most enjoyable vblog I’ve done so far may be more to come like it.
Time to get busy NO MATTER WHAT. Had a great weekend spent with my son and family, we even did a little coding using the reddit API. Sunday was cool too, I managed to grab some bargains from a few second hand sales, nothing exciting or tech related, just a few books on survival/bushcraft/scouting. Today im going to attempt to record the SDR# video as the last time I forgot to hit record! (*not quite I forgot to hit record but that’s another story/rant), I’m also ready to go war driving so that might be a thing in a few hours. Had some more breakout / dev boards turn up in the post but not the one I’m waiting for, lol, its always the way.
Nothing ever goes as planned, I went for a little war drive earlier after having installed kismet, gpsd-clients and gpsd. Recently I reinstalled debian with lxde and I couldn’t figure out, or seem to kill the gpsd process to set my gps as the default device (/dev/ttyUSB0), no matter what I did couldn’t get kismet to detect the dongle in gpsd or even find the configuration file. I decided to run kismet with the –use–nmea option BUT this was a lot less reliable in kismet than what gpsd usually is. Then my netbook went to sleep as I havent figured out the power saving settings in lxde yet. (I’ve been using lxde less than a week) I pulled over to restart my scan but accidentally chose the wrong wireless device when I restarted kismet, so all in all a complete mess. That said I’m working on a little script to load everything at once correctly so this won’t happen again. I really newb’d out tonight, If at first you don’t succeed try harder.
sudo kismet -c wlan1 -use-nmea-gps /dev/ttyUSB0 -gps-reconnect true
DO NOT USE THIS FOR GPS IT SUCKS … I had the most sketchy log files using this syntax to call kismet. Might have been the way I had the dongle positioned but I think its the way netxmltokml process the file when its been generated using that switch.