Default Green Orange
Marcus Follrud
Wish I had a slogan
RSS
  • Home Page Home
  • Cruel Chipmunk Productions
  • Om
  • Projects

Axis Parameter Class for Python

Open source, Programmering 0 Comment »

A couple of days ago I was in need of making some scripts that removed duplicate parameter groups on a couple of Axis devices. For those of you who don’t know, Axis creates Digital Surveillance Cameras with IP technology, which in practice means that It’s surveillance cameras running Linux.

All Axis devices offers an open API for developers who want to develop  that uses Axis devices. The most frequent API used is the Parameter API, that allows to change basic settings, create motion detection windows, events with triggers and so on. And this is the API that I had to implement a class for.

The class is written in Python and is pretty much an object oriented interface. Example

param1 = AxisParameter("Motion.M0.Left","1120")
#param1.name = Motion.M0.Left, param1.value = "1120"
param2 = AxisParameter("Properties.Resolution")
#param2.name = Properties.Resolution, param2.value = None

Here we have two parameters that can be accessed from the class. param1 contains a parameter with an assigned value to it, this can be used to modify an already existing parameter. param2 contains a parameter name, but have no idea of the value of it, better used to receive the parameters

To use the class, you must first import the data from it.

from AxisParameterClass import * #import both the working class and the information class

paramclass = AxisParameterClass("some.ip","username","password","vapixversion")

All arguments are optional and can be set later with the following functions

  • setIP
  • setCredentials
  • setVapixVersion

Axis currently have two API’s for handling vapix parameters. The only big difference is the URL, but still. The class will automatically try to determine the vapix version if not set before.

Receive parameters

To get parameters from a device, simply create a parameter that you’re interesting, both groups and subgroups are fine to use:

paramclass.getParameters([AxisParameter('Motion'), AxisParameter('Properties'), AxisParameter('NonExistent')])

The class will return a list of all parameters that matches the search. Is a parameter not found, the Parameter will be returned with the value None. All parameters that are found have their value as a string.

Remove parameters

Just as add. Create your list, and send to

paramclass.removeParameters([AxisParameter('Motion')])

Parameters returned have a status parameter that refers if the parameter was removed or not:

AxisParameter.status = "OK" #removed
AxisParameter.status = "Error" #not removed.

Update Parameters (Implementation still needs some work)

To update, pass the list into

paramclass.updateParameters([AxisParameter('Motion.M0.Left','1123')] )

If all works, the parameters returned will contain the same result as what you passed in.

 

Download

It can all be downloaded from github, licensed under MIT, so feel free to do whatever you like with it :)
https://github.com/marcusfollrud/AxisParameterPython 

la la laaa
  • Facebook
  • Twitter

januari 24th, 2012  



Annoyed with WordPress

Linux 0 Comment »

Yesterday I was faced with a problem from a friend who has a wordpress blog hosted at wordpress.com. The problem was that the 3GB space on the blog was filled up with the images to his blog posts. The reason that it was already used was due to the fact of that the images were uploaded with their original size, which are of course with todays cameras kind of big.

Got me thinking. WordPress already offers the functionality of scaling images in the Media Library, but doing that one by one is very time consumin, and to be frank, it’s extremely boring :-) , this took me onto google to see if there’s any xmlrpc api function (since WordPress supports this) that would let me do so. No, but I can upload images using wp.uploadFile, and it seems to support overwriting. Great!

Or was it? No. Firstly, the overwrite functionality doesn’t overwrite the particular image you’re interest in overwriting. It creates a new one, and removes the old one not even the name in the database is the same, all of a sudden it includes some sort of reference name to the old file, that you’re obviously interested in.

Piece of code:

if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) {
			// Get postmeta info on the object.
			$old_file = $wpdb->get_row("
				SELECT ID
				FROM {$wpdb->posts}
				WHERE post_title = '{$name}'
					AND post_type = 'attachment'
			");

			// Delete previous file.
			wp_delete_attachment($old_file->ID);

			// Make sure the new name is different by pre-pending the
			// previous post id.
			$filename = preg_replace('/^wpid\d+-/', '', $name);
			$name = "wpid{$old_file->ID}-{$filename}";
		}

As can be seen here when overwriting, we look up the old image (based on the parameter $name) and deletes the file from the upload directory, but take a look at the next couple of lines. WordPress choses to create a new table row in `posts` with the old filename based on the old id and then adds a new filename.

For me, and everybody else who just wanted to replace/edit their image without  a huge hassle all of a sudden got a lot more work to do. Instead of having the same url to the image there’s a new one, if folder were used for adding images to posts (etc: /wp-content/uploads/2011/09) which results in that we have to edit all the posts who directly link to the image and not just a media library entry.

Why didn’t WP just replace that particular file in the system, as we actually were interested in overwriting it. Ah well, editing the posts shouldn’t be too much of a big mess right? Nah, editing a post isn’t hard at all. Download all the posts with getPages and just replace the old url with the new one for the images (even if a post from 2010 will have image links to 2012, not very stylish)

Oh, and another thing i noticed. When using wp.uploadFile the $name parameter must add a file type prefix, such as ”.jpg”, or it won’t be uploaded. This is not a big problem, unless you wanted to overwrite an image that was uploaded from the web GUI where your description ended up being ”Hello donkey kong” without an file type prefix. That file won’t be able to be overwritten (replaced) by another image.

So basically, I can’t achieve what I want, and it really annoys me.

Of course, the best way of achieving this is to just use  an FTP server, download the images from their folders, scale them with imagemagick or any good piece of software out there and just upload them again. But wordpress.com doens’t support FTP:ing, which I’m totally fine with, and totally understand.

Ok. WordPress is the greatest blog platform out there, so far I’ve never had any hassle myself as I have complete access to the system, but I don’t have that, It will lack some features that I’d like to have :(

I could just write a plugin that does this, but as I cannot upload plugins to wp.com that approach also fails. I’m locked out of doing my scaling on the images, unless I want to be a script kiddie and use the AJAX interface with Wireshark traces and somewhat reverse engineering but this isn’t the right way of doing things.

I think I’ll just sit down, add a feature to scale images on class-wp-xmlrpc-server.php and if I’m lucky, it’ll end up on the official release for wordpress.org, and it might work on wordpress.com as well one day, at least that’s what I’m hoping for, so that all the rest of you guys can get your used space down a little bit!

/marcus

la la laaa
  • Facebook
  • Twitter

januari 18th, 2012  



presenting mfTabata

Linux 0 Comment »

Some posts ago i wrote about my experience with Android development and the result of my learnings, I took the time to fix some minor bugs and make the application running. It wasn’t too hard, even though there might be some more bugs to it of course.

It’s called ”mfTabata” (naming things is the hardest part :-) ) and runs on all Android devices running version 2.2.3 or more (that’s all I’ve tested).

I’ll publish it to the market soon, but for now you can find it on the blog

Cheers

 

 

 

 

 

 

la la laaa
  • Facebook
  • Twitter

september 4th, 2011  



dopingkollen.se

Open source, Programmering 0 Comment »

Hej Vänner!

För några dagar sedan hade jag och några vänner en diskussion kring kosttillskott och ”misstagsdoping”. Finns misstagsdoping egentligen? Behöver man kosttillskott? Frågorna var många och vi hade väl ungefär lika många svar. Men samtidigt som jag var mitt uppe i diskussionen pågick där parallellt en härlig problemlösning i bakhuvudet som bara kommer fram vid programmeringstillfälle. Hur skulle det vara ifall man hade en databas som hade koll på vilka produkter som var stämplade som dopingklassade?Med innehållsförteckning, länkar mot nyheter osv osv?

Av att döma utav Riksidrottsförbundets lista på medel som inte är tillåtna blir man lätt blind, och t.om ger upp. Där finns helt enkelt inget bra sätt att se ifall ett kosttillskott är dopingklassat eller inte.

Samma dag som diskussionen satte igång var jag fullt igång med att göra något av det. Tekniskt intresserad som jag är lade jag nog mest tyngd på vilka komponenter jag skulle använda. Valen blev följande:

  • DooPHP
  • jQuery
  • mySQL

DooPHP blev valt av den anledningen att det är väldigt komplett, men ändå förvånansvärt snabbt och enkelt att använda.
jQuery för enkelheten med JavaScript och dynamiska webbsidor.
mySQL var lika enkelt att välja, jag behöver bara en enkel tabell med korsreferenser. sqlite hade säkert funkat, men DooPHP har grymt stöd för CRUD och tabellrelationer, som inte verkade vara helt stött med sqlite.

Så, jag satte mig ner och började skrida till verket. Efter några timmar har jag en sida uppe som ligger på http://dopingkollen.se.

Dopingkollen är en kollaborativ sida där alla kan söka, ändra och lägga till produkter. Det som behövs är produktens titel samt dess innehållsförteckning. När produkten finns i databasen jämförs den direkt med RF’s lista och ger information ifall produkten gick igenom eller inte.

Enkelt och smidigt, men designen behöver jobbas på, och det gör jag :) .

Förutom sidan i sigsjälv är där ett API, se http://dopingkollen.se/api, gjort i REST + JSON, för enkel och bandbreddssparande implementering.

Så, nästa steg är att gå igång sidan i sin enklaste form, vara nöjd med designen. Därefter blir det ett nytt spännande projekt som jag tänkte låta vara Open Source, en Android app som implementerar zxing, där man kan använda sin mobilkamera för att skanna en EAN-kod och därefter får resultatet direkt i luren när man står i affären och ska bestämma sig för vilket kosttillskott man funderar på att köpa.

 

 

la la laaa
  • Facebook
  • Twitter

augusti 28th, 2011  



Goals of 2011

Linux, monotouch, Open source, Programmering 0 Comment »

Haha, just read my old post regarding the goals I had set in 2010. Did any of them come true? – No.

This is how it went:

#1 MonoTouch app
I did start an iPhone application with MonoTouch, but the API for the application is was developing on never got completed so it just died. Would’ve been a great app that’s for sure

#2 Payson drupal module.
Also got started, even got quite far actually, but my leaving of the drupal site I was part of (linuxportalen.se) resulted in a non-complete code. Besides, I have a shallow memory that there were some problems with drupal when it came to directly hook into POST parameters, which were needed by the Payson API. When i think about it I should’ve just made a hacky php that connected to the database with the proper result, but if I’m not mistaken mind was set to do it ”the proper” way, which resulted in a no go.

#3 Community site based on Django
Ah, i really loved python back in early 2010, and I still do, but when I did some research I found tornado server of better use, as I started to more and more like to writer proper API’s, instead of views with hooks of code.

I stopped with the Django project after some time, got back to PHP, created a small framework and started developing the new community site, which also kind of died along with my interest in the Swedish Linux community (yeah, it was meant to replace linuxportalen) whom were too much interested of internal conflicts plus distro war.

But, through the year I looked up some different Web frameworks for PHP, and I found DooPHP, a wonderful and fast framework which is easy to learn and use. There’s a small project going on there, without a release date though, just something I do when I’m bored.

So to sum it up, none of my plans happened with the spare time I had part from my ordinary job, but it’s ok, none of them were too important, even though it looked like it when I think back about it.

 

Goals of 2011
Ha ha, right, I won’t set up any goals this year. I spend far too little time in front of the computer when I’m not working and the truth is, there are other things in life far more important to cherish and enjoy besides techie stuff. But hey, do I find something not too big and fun, I’ll probably do it :-) .

Take care,
Marcus

la la laaa
  • Facebook
  • Twitter

augusti 15th, 2011  



Spotify invites

Linux 0 Comment »

I do have a lot of spotify invitations to give away.

let me know if you’re interested in one, drop me a mail to marcus.follrud @ gmail

la la laaa
  • Facebook
  • Twitter

augusti 15th, 2011  



Developing with Android

Linux 0 Comment »

Sunday of text

Sunday of text

It’s been a while since I’ve had any needs of sitting by the computer and write any code. I just haven’t felt the need of doing it, or have I thought that it would’ve been fun. Idk, I guess that I’ve just lost the fun part of developing.

Anyways, some days ago I received a new phone from the company I work for. I’ve had an iPhone 3GS since it was released and it is starting to fall apart. This time I got to choose an Android phone, and the choice came down to HTC Incredible S, which is absolutely a cool phone. And Android is such a cool operating system. I really get what people mean when they say that they feel locked in with Apples iOS. Without jail breaking it, you don’t get all the nice stuff you might want, like the widgets, bit torrent client, SCP data transfer and all the media codecs. The list comes quite long if we’re suppose to write everything down what Android has and what iOS doesn’t, so lets skip it.

I still like iOS though, it’s really a great operating system as well.

So, after using the Android OS for a while I decided to look into the development environments of it. I knew it was based on Java, which I’m not too fond of, not due to it’s language, but to the performance, if it wasn’t running on Windows, it was terribly slow. But for Android, I was completely wrong, It responds fast, and it reminds a lot of C# (duh). So today I decided to do something for Android, just to see how it works. I chose to make an Tabata, or Interval sprint timer, that give you a honk on the horn when to sprint or to rest. From idea to working app in the phone was about 5 hours. I’m amazed how fast it went, for not having done too much development in the last months.

Below you can find a video of the result (P.s my writing feels like crap, it’s been a while since I expressed my mind on the keyboard :) D.S):

IMG_0002

 

 

 

 

 

 

la la laaa
  • Facebook
  • Twitter

augusti 14th, 2011  



Adding bit.ly support to mu-feeder

Linux, Open source 0 Comment »

My twitterfeed haven’t been working for  a while now. The last update was 2009-11-25, so I went out googling on ”twitterfeed replacement” and found mu-feeder. A small python script that publish your blog entrys (or whatever RSS feed that you might have) to twitter. It’s very sweet but i missed the bit.ly support.

But, since it’s open source, there’s nothing that you can’t do about it :) . I went out hunting and i found python-bitly. A library for the bit.ly API!

After some tweaking in the bitly file I got it working.

Step 1: Download mu-feeder and unpack it.
Step 2: Download the modified bitly file and put it in mu-feeder/shorteners (diff here)
Step 3:  Edit your mu-feeder settings.py. set URL_SHORTENING_SERVICE to ”bitly” and URL_SHORTENER_LOGIN plus URL_SHORTENER_PASSWORD to your bit.ly username and the API key that you have on bit.ly.

That’s it. Now it should work just fine :) .

Have a nice weekend.
Marcus

la la laaa
  • Facebook
  • Twitter

januari 23rd, 2010  
Tags: bit.ly, mu-feeder, python, twitterfeed



6 Spotify invites

Privat 11 Comments »

Hi folks. I have 6  invites to spotify. As always, enter your email in the comment and I’ll give you a ”Spotify Free” invite.
First come, first served.

Oh and yeah. I will delete the mail info asap.

Yeah… I’m out of invites.

la la laaa
  • Facebook
  • Twitter

januari 18th, 2010  
Tags: free, invites, spotify



2010 – Goals for the year

Linux, monotouch, Programmering 2 Comments »

I didn’t make any new year promise to myself. Mostly because there’s nothing more broken than a promise made when welcoming the new year. So, instead of making promises, I’ve made goals that i’ll try to complete and deliver.

#1 – My first iPhone application released

A couple of months ago I beta tested MonoTouch, the .NET framework for the iPhone. It’s a great tool for all of us who doesn’t want to learn Objective-C. After some testing I started to do some actual work for an application. It still needs  more work to be functional but at least I have something to go on. I all goes well this will be done somewhat in April.

#2 – Payson Drupal Module

This one is a bit disturbing and embarrasing. For a long time I’ve wanted to make this module for Drupal where you, as a user have the possibility to sponsor sites by paying a small amount of cash using paysons money transaction system. I like Payson, and it really deserves more focus :) . Hopefulle this will come handy to Drupal site administrators. Hopefully this will can be expected in fall of 2010.

#3 – Community Site based on Django

The Swedish Community has for a long time lacked a good community web site for tracking one of the finest things with open source – The great open project that makes whatever disitribution worthy of. It can be all from background search engines like beagle to music players like Listen. All small components that makes the linux experience that great! This should be expected in late 2010.

That’s the three prioritized goals that I have as it is right now. I’ll end this post now to get started :) .

See you!
/Marcus

la la laaa
  • Facebook
  • Twitter

januari 1st, 2010  
Tags: django, drupal, iphone, monotouch, php, python



Previous Entries
  • Kategorier

    • Linux
    • monotouch
    • Open source
    • Planet
    • Privat
    • Programmering
    • Spel
  • Arkiv

    • januari 2012
    • september 2011
    • augusti 2011
    • januari 2010
    • december 2009
    • november 2009
    • oktober 2009
    • september 2009
    • augusti 2009
    • juli 2009
  • Etiketter

    2.6.30 16f690 Andjelka ANSI C apparmor apple axis biltema blommor c# curl debian despotify django drupal inaktivitet iphone kde Linux linux mint liseberg mono monotouch novell Open source php pic pic16f690 plasma plasmoid Programmering pump pykde pyqt python qt sdcc sommarstuga spotify spytify vatten vattna blommor virtualbox wordpress youtube
Copyright © 2012 Marcus Follrud Acne treatment
XHTML CSS Logga in