Thursday, 26 August 2010

Appliance control using a mobile phone and SMS messages, part 1

Hey, how are you doing? (: Since there was a week between the end of the GSoC and the start of my studies, I decided to do some hobby hacking.

I have some remote (50 km away) appliances (electric heater) that I would like to control from wherever I am. The SMS service is a very compelling solution for this kind of problem. The main challenge is to figure out how to make a mobile phone to a relay that can switch on and off things.

I found a nice tutorial here which tells how to control a 12V car relay with a vibrator signal from the phone (no firmware modification is involved there). This gave me a good jump start. I picked up my old Nokia 3310 for this job. One nice thing about this phone is that it has a thermometer that is mounted in the battery (only original batteries have these). The thermometer will tell what is the current temperature around the phone. The phone will use this information to decide whether to turn on or off the heater in order to keep the same temperature in the room. SMS messages will be used to notify me if something goes wrong or to change the preferred temperature. This can be used during winters when you want to preheat the place before arriving there. Another advantage of this phone is that there is a marvellous open source tool called NokiX, that allows to modify phone's original firmware.

First of all I modified the phone's F/W which turns vibra on and off according to the environment and preferred temperature. You develop these patches using C or Rexx. There is quite a lot phone functionality exposed already. My application does the following things:

  • turns the vibra on or off according to the temperature readings
  • you can give a ping to the phone (call the phone for one signal and then hang up), and then the phone will send you the current temperature
  • the phone will send you a message when temperature drops down below a certain limit

After that came the hardware part.
Don't mind the labels in the picture above. I wanted to place all the components in a quite an optimal way, so I created a PCB design first. It is quite compact but I still could not get rid of one wire going on the non-component side of the PCB.

You can notice a misturned transistor in the pictures above. Thankfully my dad noticed it before I plugged this thing on. After I completed soldering this board a time came for the modification of my good old Nokia 3310. What I needed to do was just take that mobile phone apart, take that vibra motor away and solder two wires in its place.

Then I needed to make a little hole in the plastic frame so these two wires can get out. I did all of this following pictures from the link mentioned in the beginning of this post. After I put everything back together I measured the voltage of the vibra motor. According to the site it should be around 3.75, and so it was.
So far so good. But there was one problem when I connected the phone, power supply and relay to the board. Relay was always on disregarding the vibra power of the phone. I measured the voltage on the relay and it gave me 6V when vibra was completely turned off. Well I am not that good in radioelectronics so I asked my dad for some help while debugging the situation.

After couple of voltage measurements we decided to put a 68ohm resistor between the base and the emitter of the transistor. This helped. When the vbra power was off the transistor was completely off and relay voltage measured 0V. When the vibra was on full power transistor was completely on and relay voltage measured near 12V. This modification was needed because we used a different kind of relay than the one mentioned in the article.

This left us with a working bunch of wires and components on the board. Tomorrow I will try to put everything into a nice box. See you then.

Sunday, 15 August 2010

GSoC 2010 Week #12 report

Hello everyone,

well it has come to the end. This is my last GSoC 2010 weekly report. First of all I would like to say that it was an unbelievable experience to work whole summer on the open source project such as phpMyAdmin.

Well talking about my initial proposal to phpMyAdmin not everything that was written there is implemented. Two out of the three main goals are completed. Now any user can see and create charts out of their data and I believe that I did quite a good job giving future developers a way to expand chart implementation with different chart renderers.

One thing that was in my proposal and I left it out is JS chart implementation. I dropped it because image charts looked so nice and I was able to add some interactivity (tooltips) to them which are probably the most used feature of JS charts.

I spent the last week rewriting comments so that phpdoc can understand them. I also added some documentation and linked wiki to the FAQ section of the documentation. So any user that has a problem while drawing a chart can seek help there.

Well I haven't had a blog before GSoC, but I will try to keep on posting what is happening around me. See you some time later!

Sunday, 8 August 2010

GSoC 2010 Week #11 report

Hello everyone,

well not much code was added this week. However I have tried to install my PMA fork to as many machines with as many configurations as possible. By doing so, I have found few bugs and made some fixes which will help with the compatibility.

Who would have ever thought that I would find a machine with no JSON capability. After this not usual encounter I added check for JSON functions and if there are not any, then tooltips are disabled.

Next week is the last week of GSoC and I will work on documentation, more testing and fixing bugs if any.

Saturday, 31 July 2010

GSoC 2010 Week #10 report

Hello,

well I spent this week fixing various bugs and polishing some details. One of the more significant achievement was more sophisticated tooltip generation. Now it should work on any pie chart. Even on one with only one piece.

I have solved the base64 image length problem that I described in my last post. I decided to slice the chart image vertically into as many as 20 parts. In such way one part of a very big chart is under the limit of the base64 image length so it is displayed properly. This added some difficulties for the user when saving the chart to the hard disk. Therefore I have also added an option which allows to output a chart in one single piece.

I have tested various trivial cases for tables and checked if query results work on them. There was some tweaking to be done for these cases.

I also documented some work I have done in the wiki. You can find it here. There is also a format documented that is accepted for query results charts. You can see the preparations that need to be done for your data if you want to put it to the chart.

I have also merged master to my fork. There was only one minor conflict. This actually means that I am not changing PMA code much. I am just adding some new.

Next week I will continue polishing and fixing bugs if any.

Thursday, 22 July 2010

GSoC 2010 Week #8-#9 report

Hello,

first of all sorry I missed the report of the week #7, but I was ill that week so nothing much happened. This week I have started adding JS to the charts. So this is how it went.

The PHP library that I use (pChart) for chart generation has some ImageMap functionality. What it basically does is return some data to JS where a tooltip must be shown. That data is only coordinates of two points. That script allows to show tooltips only above rectangles. Well, pie charts and radars charts consist of not only rectangles but we want tooltips on them too.

So I started this week by writing some PHP code which calculates the areas where a tooltip should be on a chart and then JS had to be improved to cope with more complicated figures. There was some interesting math involved in this. Now we have tooltips over pie and radar maps too.

Well with JS sometimes comes compatibility issues. So when I started writing JS I also have started testing my work on other browsers. Only now I have noticed that IE 8 (I haven't even tested it on older ones) does not always show base64 encoded images. Some images which have long base64 strings are not shown. This is a little show stopper because I have no idea how to fix this without scrapping base64 images.

Talking about charts (: I was thinking about and looking at flot library for charts. It is not really suitable for this. It does better job while rendering plots than charts. pChart does render really good looking charts and no other library can do it better. I am not sure if PMA needs another implementation (JS) for charts. I think now I will do my best to add some convenience JS functionality and it will be much better than completely different JS charts implementation.

Now I am going back to tinker around with details and some bugs that are still there.

BTW. You can test out the chart functionality here. Just go the the status page and you will see nice looking pie chart. It is harder to test query results charts because you need some data which script does understand.

Sunday, 11 July 2010

GSoC 2010 Week #7 report

Hey everybody,

quite a lot have happened this week. Let me have a peek to the commit list...

Aha. First of all I have found one serious bug that was present in the demo server. There was no GD extension installed there. Not quite a bug you may say, but it took me some hours to figure that out. So then I implemented some error checking and notification.

Besides error checking I changed the structure of some classes responsible for charts. This helped me to introduce new chart types quite easily. Now you can choose among bar, line, radar and pie charts for query results chart. I am still not quite happy with the new structure. There are some places where I would like to use multiple inheritance. But this only says that the design is not perfect.

Next week I will start the implementation of JS charts using flot. So for now static image chart code will stay as it is. I believe I will have to change it in some way or another because I would like to have image and JS charts looking similar, but JS charts having interactivity. I am really looking forward to this part. JS is always somewhat challenging to me. (:

See you after week!

Tuesday, 6 July 2010

GSoC 2010 Week #6 report

Hello,

as I said earlier I was away for the whole previous week. Now I am back ready for some coding action.

This week I will iron out the problems that the demo server has with the charts. I have tried to do this old-fashioned way and by now I believe that there is something to do with different GD versions. Because of this I will also add some version checking and error message generation to the code. It is always good to do this before any errors happen or you can loose some time while hunting bugs as I have.

After this I think I will be ready for JS chart implementation.

Take care,
Martynas

Friday, 25 June 2010

GSoC 2010 Week #5 report

Hello all,

this week was spent implementing charts for the query results. As mentioned in my latest blog post I implemented rendering charts for the query results in two formats.

The branch that I am working on is available here. Unfortunately charts are broken there, even they work on my local web server. I have yet to find what is wrong.

This week was a very short week for us lithuanians. On Thursday and Friday we have celebrated mid-summer which is a national holiday here. I will be taking the next week off because I will attend at social experiment.

I will be back to business the week after. Then I will be getting ready for JavaScript chart implementation. Can't wait! See you then!

Tuesday, 22 June 2010

Query results chart

Hello,

while the code for generating charts for the status page and the profiling page was more or less trivial, code for the query results will be more complicated. This is because of the dynamic data structure that query results can have. You can get any number of rows and columns as a result. Also the data in the result is composite - there are strings, numbers, dates, etc.. Not everything is suitable for one chart or another.

I decided to introduce two (for now) query result formats that must be followed when you want to put your data to the charts. If this format is followed code will recognise that and will render a chart which suits best.

For now I will be talking about two types of charts: simple bar charts and stacked bar charts. For the simple bar chart we need to provide X and Y axis value pairs, something in a lines of this:

MonthSum
2009-11225
2009-121157
2010-01569
2010-02282

You could imagine now that the chart for this table would look like this:


Now this is easy. What if we know that the total amount on every month is composed of different parts and we would like to see them in the chart as well. For this we will have to add another column which specifies which component the data belongs to. This breaks the monolithic bars into the bars composed of series of data.

MonthSumOperator
2009-11129Bite
2009-1140Omnitel
2009-1156Tele2
2009-12176Bite
2009-12707Omnitel
2009-12274Tele2
2010-01422Bite
2010-01108Omnitel
2010-0139Tele2
2010-02110Bite
2010-02131Omnitel
2010-0241Tele2

For this data generated chart would look like this:


Note that for both charts labels for X and Y axis were taken from the column names. It is nice to have such details taken from the query result. However I would also imagine that some users would prefer to set details like these in the chart generation page. I will be adding some options there which will have default values but will give the ability to change them to whatever you like.

So If you would like to put your data to these gorgeous charts generated by pChart just write a MySQL query which puts your data to the formats described above and you are done. Any other chart types which are suitable for query results?

Sunday, 20 June 2010

GPRS internet on your PC using a mobile phone modem

Hey,

I have thought for some time that it would be quite cool to have the internet anywhere you go using the GPRS network. All of us carry some mobile phone device. Not all of us know that almost every mobile phone can be connected to the PC and be used as a modem for GSM or even GPRS data transfer. Even better, mobile phone can be connected to the PC using Bluetooth - no unnecessary cables! When I saw that my carrier (Tele2) allows me to use 1 GB for 1 LT (~3.5 EUR) every month I decided to figure out how to put everything together.

The first thing I did was download mobile internet settings from my carriers web page and set the new connection as a default one in my mobile phone. Then I have found quite a good tutorial in the carriers home page. It basically deals with how to set up the dial-up connection on Windows XP using GPRS through a mobile phone. You can find it here (mirror). This is in lithuanian but has many pictures so it is quite easy to understand the general idea.

However there was a catch. I did follow every step from that document but with both my mobile phones I got the Error 31 when trying to connect. As I have discovered later this was due to not set GPRS APN setting in my mobile modem. To set it you will have to connect to your mobile phone modem using some terminal program. I have used puTTY.

First of all you have to know the COM port that your phone modem has been assigned to. You can do this by clicking twice on newly created dial-up conenction and then Properties.

The port that I want to use happens to be COM27. So fire up puTTY, select Serial as connection type, type in COM27 as serial line and click Open. Black screen will show up. To test the connection type in AT and press enter. If OK shows up you are good to go. Note that some mobile phones require a confirmation when someone is trying to access their modem through Bluetooth or USB.

The mighty command (I found it here) that you have to enter is: AT+CGDCONT=1,"IP","<YOUR GPRS APN>". I do not really know why does this do the trick, but it does. (: If you did everything right OK will show up. You can check if this information is saved by typing in AT+CGDCONT?. I have noticed that this information stays saved even between mobile reboots. So it seems that you only have to do this once.

Now close the puTTY window and give a few seconds for a mobile modem to close the connection. Then try to initiate dial-up connection from your PC and emerge into to the meadows of not so fast internet.
Now whenever I have my laptop in the wild with me and I need connectivity for one reason or another I just activate Bluetooth on my phone and that's it. I have tested this with two not so new and shiny mobile phones - Motorola E398 and E2. Both have worked but the connectivity was not very stable. There was about 40% of dropped packets when I was pinging to google.lt. Nevertheless it is better than nothing. (:

This was my little adventure on an early Sunday morning. See you.

P.S. I posted this from my notebook using GPRS internet. (:

Saturday, 19 June 2010

GSoC 2010 Week #4 report

Hej,

there has been quite a lot of activity happening this week. First of all after some discussion I have scrapped the flash implementation of the charts. We have decided that the same chart functionality can be achieved using JS. And since JavaScript is still needed to load the data to the flash charts it does not really make much sense to have flash and JS.

This week I have implemented static image charts using pChart library. Before that I thought of implementing image charts by myself. However after stumbling upon (tm) pChart I have changed my mind. For now charts are working at the status and profiling pages. I have some code to generate charts from the query results, but I will push that and write a blog post completely on that a little bit later. These are still more or less prototypes. I do feel that it is better to try different approaches and be not afraid when deciding to go or not to go in some particular way.

Working with pChart library is quite nice. Everything is in one file hence the very easy installation. Charts look sleek and clean. The only drawback is the chart generation type. It feels that it takes extra one or two seconds to generate a chart.

During the next week I will be working on the charts for the query results. This is the most tricky part. Data is quite dynamic there and generally can be anything, thus I have to make sure to not get the user lost. More on that later...

Take care.

Monday, 14 June 2010

GSoC 2010 Week #3 report

Hello,

I am finally done with travelling and all the progress that I made last week is the progress made today. As promised I implemented the Pie chart using OFC for the query statistics.

I have put the flash file which is needed for OFC into the js/ directory. The name of the directory does not say that this is right. I believe that it should be placed into flash/ directory, but since there is no such yet (it seems that there was no Flash in PMA until me) I will temporarily keep it there.

To embed SWF file into the page I did not use SWFObject script but rather plain and simple HTML tag. I remember when some time ago this did not work correctly throughout all the browsers, but today I have tested this on every major browser using the latest version and I didn't notice any errors.

For this week I will add Pie chart to the query profiling statistics and will start working on other types of charts using OFC.

The colours and layout are not yet final. I still have to find the best place to put javascript enabled and plain image charts.

Friday, 4 June 2010

GSoC 2010 Week #2 report

Hi,

I have created a wiki page where I will post all the details about the implementation. This page will let you to get an overview of how I will move towards implementing ideas.

I have also started creating placeholder files where all the fun will take place. I try to follow the file naming and coding standards, so that I do not make a mess out there.

This is the link to the pma fork that I am working in. I believe I did not mention that earlier.

Now, when everything stands in their place, the goal for the next week is to tie in the OFC code into pma.

P.S. I decided to use NetBeans. It works great with PHP and it is the one that I have most experience with when developing PHP code.

Monday, 24 May 2010

Coders, start your IDEs!

Hey,

today is the day when students all around the world start to officially write code and blogs for Google Summer of Code project. This also has to include me. I am a little bit sad to say this, but my RPMs will not be rocketing to the skies for now. I have two (yes two) exams on Friday. For now all my thoughts are with these two, and with another project work that I am doing with my course mate.

But still, I spent some time setting up my development environment. I have successfully created a fork of phpMyAdmin code in repo.or.cz for all my coding needs. When the time came to set up git in my Windows machine I ran into one little problem. It seems that puttygen does not generate private/public keys in the exact format that ssh (on msysgit) accepts. Well this little thing cost me about an hour. |:

I am still not sure what IDE to use. For hardcore PHP projects I used NetBeans. It was a long time since I worked on any huge PHP project so every time it was enough to fire up FileZilla and Notepad++. I had a couple of Java projects this year and this is why I had to start using Eclipse. Still not really sure if that is good working with phpMyAdmin.

So for now this is all the news. I will keep on doing my school chores. Next Monday I will have some serious coding blog post. See you then.

Tuesday, 27 April 2010

Google Summer of Code 2010

Hello world!

Well so happens that I have been selected to participate in the Google Summer of Code 2010 under the "Charts in phpMyAdmin" project. This is actually the main reason to start this blog, although I wanted one for a long time now.

I am really excited about GSOC. Yesterday around 19 o'clock UTC it was really fun to watch and to participate in a #gsoc IRC channel at freenode. All these students talking nonsense and really getting exciting no less then I was. And then after results came in jumping and shouting in my room for about five minutes (wonder what my neighbors thought...).

Anyway it was great to be selected, I believe it will be even better experience to participate. Now it is the community bonding period. So I better go and bond a little bit. By the way, yesterday one student after being selected asked if drinking beer together with mentors counts as community bonding activity. Nice thought to leave you with.

Take care.

P.S. My original proposal can be found here.