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

Open source Category

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 


januari 24th, 2012  



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.

 

 


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


augusti 15th, 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


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



Say hello to Moblin

Linux, Open source 0 Comment »

Today I downloaded moblin, as it were supposed to be good for netbooks. After I’ve testing it for awhile I can’t do anything but agree. It’s really that great!

It everything that a good os needs, and all the applications seem to be highy integrated in the main interface!

Try it out at: moblin.org!


november 9th, 2009  
Tags: Linux, moblin, netbook



Debian in Virtualbox

Linux, Open source 0 Comment »

In the Swedish linux community, it’s quite common to experience linux by:

  1. Install ubuntu/opensuse/mint
  2. Fix the lack of mp3/mkv/h264/xvid blabla support
  3. Install virtualbox
  4. Test distributions
  5. Brag about the ones you installed (especially Debian)

It’s always good to try out different flavors, till you find the one the match your needs and requirements. It is also always good for people that’s creating the different distributions as it often generates feedback. If not directly towards the developers, then at least a comment about it on the web will be made in most cases. This means indirect feedback plus the growth of Linux overall.

When it comes to myself, I’ve never been much of a distribution tester. Sure, I’ve installed quite many over my 6 years running Linux. Such as Ubuntu, OpenSuSE, Fedora, Slackware, Arch, Crux and so on. But I have always tried them out fairly, in the meaning that none of them have been in a Virtualbox just to test the installation and the mp3 support in the chosen distribution. To me, the most importance thing is how productive I am.

Anyways, what I was going to say is that I made my first Virtualbox+Debian installation today (yay, my time to shine!!). To me Debian has always seemed to be this quite advanced installation to get it up and running, according to what Swedish users express on the web. . But today, I realized that it’s just as simple as installing it’s buddy Ubuntu. Why do people brag about this?

The true reason for why I chosed Debian, and more important installing via Virtualbox is because of the recent Appartment change me and my darling made I’ve only set up the MacMini as my working station. The PC is now standing doing nothing, and I’m too lazy to insert all the cables, hehe :) . Also, it’s the recommended distribution by the company that I work for. Therefor it felt naturally to install Debian!

This entry was never to start a Flame war between distributions, they are all good. It all just depends on your needs.

And if any Virtualbox distribution tester feels pointed out or accused inappropriately, then I apologize. I never meant to sound negative, rude or wiseacre.

Best,
Marcus


oktober 14th, 2009  
Tags: debian, Linux, virtualbox



Wie, jag kom med!

Open source, Programmering 0 Comment »

Häromdagen ansökte jag till MonoTouchprojektet eftersom jag fann det väldigt intressant att utveckla med. Och de snälla människorna gav mig beta access till projektet!

Skall genast testa det och ge det kommentarer, när jag har något. Men testning kan nog inte bli förräns på söndag. Om tio minuter ska vi på födelsedagsevenemang och imorgon skall vi hjälpa min syster med fästman att flytta.

Värt att notera är att MonoTouch kommer bli en kommersiell utgåva, enligt Miguel:

Commersial

För mig är detta helt ok, jag kan tänka mig att det måste vara ett kostsamt avtal med apple för att få lov att göra såhär. Mono i sigsjälvt är ju öppet, och det tycker jag är viktigast!

Jag återkommer som sagt, så fort jag har lite kod att bidra med :) .

Tills vidare refererar jag till monotouch.info och detta inlägg:

http://conceptdev.blogspot.com/2009/09/initiate-call-with-monotouch.html

Go kväll!
Marcus


september 4th, 2009  
Tags: beta, c#, monotouch



Enkelt övervakningssystem och linux

Linux, Open source, Programmering 0 Comment »

För längesen satt jag och labbade lite grann med AXIS Nätverkskameror och hur man kan spela in automatiskt med dem.

Jag försökte använda mig av bash och andra linux/gnu-kommando som jag bara kunde för att få systemet uppe och rulla.

Hur fungerar det?
Lösningen är väldigt enkel. Som första program ligger där ett script som väntar på ett tcp-meddelande som kommer in på port 31337 (nördigt va) och som därefter startar en nedladdning av en motion jpeg-ström som hålls vid liv i 5 sekunder per trigger som kommer från kameran. Det vill säga, får man samma larm under en pågående nedladdning av strömmen så läggs fem nya sekunder på innan man stänger strömmen.

Hur ställer jag in det?
Event Server SetupEvent setupBörja med att gå in i din kamera och skapa ett Motion Detection fönster. Därefter går du in till Event Servers och skapar din TCP-server med dina anslutningsinställningar. Glöm inte att porten skall vara 31337. När servern har satts upp, skapar du ett event som triggar på det motion detection-fönster som du skapat. Lägger till att det skall gå till tcp-servern du skapat och att det ska trigga ungefär 30 gånger per minut som eventet är igång. Detta gör att så länge något rör sig så hålls strömmen vid liv.

Som du säkert ser så är meddelandet en MAC-adress som är specific för varje enhet. Du måste givetvis inte döpa dina filer efter MAC-adressen men jag gjorde det för enkelhetens skull. Se bara till att du inte använder mellanrum i namnet.

Nästa steg är att installera filerna som är skapade på en lämplig plats. Låt säga att vi skapar det under en egen användare som vi döper till ”security”. Vi lägger filerna i hemmappen, packar upp och skapar mappar.
/home/security:$ tar xvf supersimpleNVR.tar.gz
/home/security:$ cd supersimpleNVR/
/home/security:$ mkdir settings && mkdir captures && mkdir captures/tmp && captures/processed_captures && tmp

Det du ska göra nu är att gå in i settings mappen och skapa en fil som heter precis det meddelandet som du angett i ditt event i kameran och med filändelsen .sh. I mitt fall blir det 00408C630000.sh

I denna skall innehålla:

  1. #!/bin/sh
  2. user=root
  3. pass=pass
  4. fps=5
  5. ip=192.168.1.15
  6. port=80

Ändra allting så att det passar med dina inställningar och behov. Glöm inte att filen måste finnas i mappen som heter settings.

Mappen captures innehåller alla dina inspelningar och mappen captures/tmp används för att extrahera bilddata i sparade strömmar.

Vad ska jag med mappen captures/tmp till?
Mjpg kan ställa till det när det gäller lagring. Därför finns scriptet ”creatempeg” som skapar mpeg4-filer av nedladdningarna. Detta script använder ett C#-program som klipper ur bilderna ur strömmen och skapar jpg-filer utav dem.

Vanliga tmp då?
Den gör inget speciellt mer än sparar tidsstämplar för att veta när en ström startades.

Vad behöver jag för program?
Du behöver bara standardprogram för att kunna spela in.

Du behöver:

  1. Netcat
  2. Curl
  3. Mono
  4. mencoder

Begränsningar för närvarande!
För närvarande kommer filmer som konverteras till mpeg4 alltid gå skapa filer med 5fps, oavsett vad du laddat ner i. Fixa detta själv genom att sätta den fps du önskar.

Hur startar jag det?
Du startar det lättast genom att starta filen nc med screen:
/home/security/reallysimpleNVR/:$ screen sh nc
/home/security/reallysimpleNVR/:$ [ CTRL + A + D ]

Ladda ner källkoden här: reallysimpleNVR.tar

Har inte testat det på länge, och det kan hända att den måste modifieras något. Speciellt c#-koden. Använd på egen risk :)

Ha en bra kväll
/marcus


augusti 31st, 2009  
Tags: axis, bash, c#, curl, gpl, Linux, mencoder, mono, nvr



Vattna blommorna – del 10

Open source, Programmering 2 Comments »

Nu händer det grejer.

Mitt program för min pic känns komplett. Har suttit och debuggat kod nu ikväll och kommit fram till att den lösningen jag postade nu senast inte var den bästa, för att vara helt ärlig.

Bland annat så verkar inte !RA# fungera riktigt i kompilatorn av någon anledning. Koden beter sig konstigt när detta händer. Eller har jag bara programmerat kasst?

Efter lite kodändringar fungerade det!

Koden ser ut såhär nu:

#include <pic16f690.h>

typedef unsigned int word;

word at 0x2007 __CONFIG = (_INTRC_OSC_NOCLKOUT & _CP_OFF & _WDT_OFF & _BOR_OFF & _PWRTE_ON & _MCLRE_OFF & _IESO_OFF & _FCMEN_OFF);
void delay_ms(long ms)
{
    long i;

    while (ms--)
        for (i=0; i<=50; i++) //50 iterations is _basically_ 1 ms.
			;
}
unsigned int pumpint=0; //just an int for loops..
unsigned int totalpumpms = 0; //A counter for how many ms the pump has been running
unsigned static int maxpumpms = 100000; //Change this if you are using a slower/faster pump.
void main () {
  TRISC = 0x00;	/* PORTC, All outputs */
  TRISA = 0x1f; /* RA1-RA4 input, RA>4 output */
  while(1)
  {
    pumpint = 0;
    //Start pumping water, if RA3 isn't activated.
    if(RA3 || totalpumpms >= maxpumpms)
    {
		//Do nothing..
		delay_ms(1);
    }
    else
    {

      while(pumpint < 5000) //Max pumptime is 5 secs.
      {
        if(RA3) //If(ra3) is used since while(ra3) doesn't seem to work as good with sdcc compiler.
        {
          break;
        }
	else if (totalpumpms >= maxpumpms)
	{
		break;
	}
        PORTC=0x0f;
        //As an extra marker, never pump for more than 5 secs.
        delay_ms(1);
		totalpumpms++; //Add to the total pumpmscounter.
        pumpint++; //just for this loop.
      }
	  pumpint = 0;
    }
    //Pumping done. Wait 15 minutes
    PORTC=0x00; //Close all outputs

    //Reset button must work within this time. Don't sleep for a whole 15 mins, but keep polling.
    while(pumpint <= 90000) //15 min == 900000ms. We're polling each 100ms.
    {
      if(RA4) //RA4 is the reset switch
      {
		totalpumpms = 0;
		break;
		//at this point, we have resetted the counter, and let the water start pumping again.
      }
      pumpint++;
      delay_ms(100);
    }
  }
}

För närvarande använder jag Windows 7 (ja, jag vet, det är inte omtyckt, men faktum är att win börjar konkurrera med kde och linux..) och mitt debuggingprogram blev ”Real Pic Simulator” som utförde sitt arbete mycket väl! Programmet är dock inte gratis, men en 30-dagars testversion gick att ladda ner. Och mer tid behöver jag nog inte :-) .

Som open source entusiast skulle jag kört gpsim som är det naturliga och självklara valet om man tycker om öppen mjukvara men jag tyckte inte att jag hade lust med att mecka conf-filer och tillägg för att få just min pic att stödjas. RPS fick funka ikväll, vilket det gjorde!

Nu kan jag lugnt slappna av resten av kvällen och njuta av mitt arbete :) .

Imorgon blir det att kolla nya möbler och liknande, då vår flytt har ändrats från 1:a November till 1:a Oktober/Mitten på September.

Ha en god afton. Själv Njuter jag med lite jamaicansk öl. Det är ju inne med Jamaica nu :)
/Marcus


augusti 21st, 2009  
Tags: 16f690, blommor, gpsim, pic, pic16f690, real pic simulator, sdcc, vat, vattna blommor



Vattna blommorna – Del 9

Open source, Programmering 0 Comment »

Efter arbetet idag blev det en snabb sväng inom biltema för att köpa en tio-liters hink med lock samt lite slang som kan transportera vatten. Jag passade även på att köpa mig en annan pump på biltema, den som nämnts i ett utav de första inläggen gällande mitt blomsterprojekt.

Alltså:

  • 362772 – Lock till 10L hink 9,90kr
  • 362770 – 10L hink 14,90kr
  • 15331 – Vattenslang 10Mx9mm 36,90
  • 25980 – Pentry-pump 79,90

Totalt: 142,40kr

Efter det bar det hem och testa hur fort jag tömde mina tio liter och resultatet blev prick 100 sekunder att pumpa vattnet till den nivå att den nästan torrkörts.

Detta ger mig lite modifikation i mitt program som ska ligga i PIC:en

#include <pic16f690.h>

typedef unsigned int word;

word at 0x2007 __CONFIG = (_INTRC_OSC_NOCLKOUT & _CP_OFF & _WDT_OFF & _BOR_OFF & _PWRTE_ON & _MCLRE_OFF & _IESO_OFF & _FCMEN_OFF);
void delay_ms(long ms)
{
    long i;

    while (ms--)
        for (i=0; i<=50; i++) //50 iterations is _basically_ 1 ms.
			;
}
unsigned int pumpint=0; //just an int for loops..
unsigned int totalpumpms = 0; //A counter for how many ms the pump has been running
unsigned static int maxpumpms = 100000; //Change this if you are using a slower/faster pump.
void main () {
  TRISC = 0x00;	/* PORTC, All outputs */
  TRISA4 = TRUE; /* RA4 input */
  while(1)
  {
    //Start pumping water, if RA3 isn't activated.
    //Wait for the breaking SW1
    if(RA3 == false && totalpumpms < maxpumpms)
    {
      while(1)
      {
        if(RA3) //If(ra3) i used since while(ra3) doesn't seem to work as good with sdcc compiler.
        {
          break;
        }
        PORTC=0x0f;
        //As an extra marker, never pump for more than 5 secs.
        delay_ms(1);
		totalpumpms++; //Add to the total pumpmscounter.
        if(pumpint >= 5000) //Loop until 5000ms == 5secs is reached.
        {
          pumpint = 0;
          break;
        }
        pumpint++;
      }
    }
    //Pumping done. Wait 15 minutes
    PORTC=0x00; //Close all outputs
    //Reset button must work within this time. Don't sleep for a whole 15 mins, but keep polling.
    while(pumpint <= 90000) //15 min == 900000ms. We're polling each 10ms.
    {
      if(RA2) //RA2 is the reset switch
      {
		totalpumpms = 0;
        pumpint = 0;
      }
      pumpint++;
      delay_ms(10)
    }
  }
}

Jag har inte verifierat koden än, men jag tror det skall fungera :) . Skall testa det imorgon, och i helgen ska jag göra mitt bästa för att bygga ihop den helt!
Jag vill ju ha den klar innan flytten, som förvisso inte är förräns i November, men jag vill gå vidare till mina andra små projekt.

Förresten, har ni någon bra bok ni kan rekommendera om embedded c-programmering. Vad man bör tänka på i minnesvägar och sådär? Jag hade uppskattat lite tips på denna fråga :) .

Mvh
Marcus


augusti 20th, 2009  
Tags: biltema, blommor, c#, embedded, hink, Programmering, pump, sdcc, vatten



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
XHTML CSS Logga in