вторник, 10 декабря 2013 г.

Talking to Arduino in PHP via USB in Linux

I'm really proud of myself. I was able to comeup with the solution for the problem which is being discussed in the internet a lot - how to properly talk to arduino from a PHP script, actually from any kind of script. The problem is that Arduino resets itself when you open a connection, this is not OK and most of people just apply some harware hacking to disable this behaviour. I wanted a software solution.

Also for some reasons I cannot read arduino output using "php_serial.class" code. SO, here is my alternative solution:


  • I've created a deamon which redirects arduino serial output to a log file. This daemon can be started and stopped, on re-start it will re-write the logfile. I've done this for maintenance purposes - the intention is to clean the log file periodically, so that it doesn't grow to Gigabytes which ultimately could affect the performance of the overall solution(so, not because I don't have enough storage - I'm doing this on Netgear STORA after all :)). I've created a daemon script and an init script for this daemon. The code for the daemon script is easy "cat /dev/ttyUSB0 > /home/com_log.txt &" and that's it. Init script is more complex - you have to properly remove the log file and kill the cat process. You can download the code here
  • Once I have a daemon - reading Arduino from any places without resetting it - is super easy. But you have to read last lines if you want latest output. I've created a script which sends to Arduino a command to print the updated information about temperature and humidity sensors, then the script reads new values from the log file and saves them into the MySQL database. Here is the code
  • The script above is added to the crontab to collect temperature/humidity samples every 10 minutes
  • Then I've created a page using Google's Charts JSAPI examples with chart for each counter. Code is here.
This is how it looks like (there is still some work to do with date picker, correct dates on axis, etc.)

Now my Stora is a temperature station :) and since I have relay connected to the Arduino I can adjust temperature by switching heating on or off, but this part is later... stay tuned.

BTW, here is an Arduino scetch - it's a modified version of arduino code from UberFridge project by some awesome guy.

P.S. Please forgive me for code quality - I'm doing this for myself rather than for opensource community :) If someone want to polish the code and make it available on some communities - you are absolutely free to do this, I would appreciate a link to my blog though.


понедельник, 2 декабря 2013 г.

Talking to Arduino from Netgear Stora via USB

Weeks of investigations and code compiling and finally I found that the answer is quite simple and elegant.

  • Download original(or whatever is installed in your Stora) Kernel source. Original one can be found here http://www.openstora.com/wiki/index.php?title=Source_Code
  • Extract kernel sources from stora sources.
  • (Optional - depends on compiler that you have) I had gcc from optware ipkg installation, so I had to change the Makefile - otherwise 'make menuconfig' will tell you that mixed explicit and implicit rules.
    • Locate all places where you see something like this "$somthing: something:"
    • Split each variable before colon into the separate line and duplicate code from one into the empty one.
    • Run 'make menuconfig' if there is still "mixed implicit...bla-bla-bla" error - check the line number and do the separation trick above again
  • Run 'make menuconfig'. Do no uncheck anything(you need the kernel in it original configuration) - you need to enable experimental drivers/code (because ftdi_sio is expiremental in Stora code) and then go to drivers > USB > USB serial, enable generic and core usbserial drivers as well as FTDI driver (ftdi_sio), close and save the config
  • Run 'make modules ARCH=arm'
  • Copy usbserial.ko and ftdi_sio.ko where you store other drivers.
  • I think I also added both drivers into modules.conf or whatever is the procedure for device drivers, 'depmod -a', you know... :) this kind of stuff
  • Also I did the trick with udev rules (http://playground.arduino.cc/Linux/All), but I'm not sure it was necessary.
  • Plugin the arduino board - do modprobe usbserial, ftdi_sio if necessary (if they are not loaded already) and here you go... you can talk to arduino(it was /ttyUSB0 in my case)
P.S. After everything worked I was using screen command to test everything - it works very well with my ardu. But you can find other examples(http://playground.arduino.cc/Interfacing/LinuxTTY)

суббота, 23 ноября 2013 г.

error expected '=', ',', ';', 'asm' or '__attribute__' before

Compiling avrdude on ARM Netgear Stora to be able to work with and program Arduino board.

Solved a lot of other quite complicated dependency issues, had to compile some of dependencies myself and then stuck with this error in the subject for almost half a day.

error expected '=', ',', ';', 'asm' or '__attribute__' before

WTF!
I had 'OD' symbos in the beginning of the .c file which had includes to the .h files which failed with the error. OMG, how the hell on earth did it get there?

Anyway, for those who find my post - check the source file which has includes to the header files which are failing, then check preceeding code - something is already wrong when compiler goes into the header files.

вторник, 8 октября 2013 г.

High-altitude ballooning. Russian Edition. Part 1.

Hi,

I've decided to try high-altitude ballooning. The maximum goal is to do a ballon which can be launched to the stratosphere, do some stuff (not only passively hang in there making pictures) and safely descent to the target location(this should be the hardest thing to acheive).

Typically this hobby is quite simple - you purchase a balloon, take helium tank, fill the balloon with attached payload and launch. But in Russia, there are several difficulties.

  • It's hard to purchase proper HA balloon without spending all of your money
  • It's hard to get necessary volumes of Helium. I don't understand why major exporter of natural gas on the planet has difficulties with helium on the internal market - but that's a fact. It costs a fortune here.
I wanted to do everything really cheap, so that my example could become an inspiration for someone else.

I seperated the project into several Phases.

  • Phase 1 - cheap balloon filling and cheap balloon.
  • Phase 2 - cheap payload
  • Phase 3 - cheap control system
I already have some thoughts about all three of them and even working prototypes, but right now I'm focusing on Phase 1.

Cheap balloon is a quiestion for now - I can pucrhase 45'' baloon quite cheaply http://zatey.ru/production/prod/detail.php?ID=70273 ~ 2$, but 8' will cost a fortune - almost 70$.

According to this famous table http://www.chem.hawaii.edu/uham/lift.html, 45'' baloon should give me 500gr lift wich is enough for the start and I think I can use two of those balloons to increase the payload weight.

Cheap filling is the main task for me right now. I'm thinking about Hydrogen, coz Helium is an inert gas and you cannot get it from chemical reaction. Yes hydrogen is explosive, but I think with right safety measures it shouldn't be a problem even in case of explosion. So, I can get Hydrogen using electrolysis and from pure chemical reaction.

Electrolysis - Pros: requires only water as a chemical resource. Cons: requires electrical energy, generates oxygen on the other wire(which is not only bad that you have to separate two gases, but if mixed they could easily blow-up because electricity is very close).

Chemical reaction - Pros: easy to do, only chemicals are necessary and in relatively small amounts. Cons: exothermal reaction(some parts of generator could be melted), hazard chemicals.

I decided to go with chemical, aluminum and sodium hydroxide reaction.

Safety Note: Always use glasses and gloves, be very accurate with the reaction, sodium hydroxide is extremely dangerous thing! And hydrogen can explode. DO NOT EVEN TRY TO DO THIS AT HOME!

I did a lot of tests and found that standard liquid drain cleaner contains enough sodium hydroxide for the reaction. As a source of aluminum I tried different things, started with soda cans, but they have a protective layer which slows down the reaction. Then I tried aluminum foil and plates made of aluminum, results were great, but the reaction goes too quickly and dissolves too much heat. Then accidentally I tried duraluminum tube and the result was awesome - reaction went smoothly and not so quickly, but the volume of hydrogen was enough to fill the 91cm balloon.

This is the look of the last successfull setup (I had a bubbler, but it developed a leak, so I had to attach balloon directly to the reaction chamber, luckily duraluminum tube dissolves way less heat and reaction is going not very fast, so there almost no toxic foam, with foil it was bubbling out of every hole)


This one below is a picture of the reaction chamber. I found that this kind of plastic bottle from ice tea is the best, because I have loads of them, I can through used one away and I don't have to clean the bottle for every new reaction, actually the product of the reaction is very messy and it's very  hard to properly dispose it separately from the bottle, I'm not even talking about toxic lye which is still there.
you can see that the bottom part melted a little bit.

And this one below is a picture of the balloon lifting quite heavy rope attached to it. With this balloon lift was not great because balloon itself was damaged(lye and other products of the reaction from previous tests) and had a lot of water on it (it was raining that day)

So, now I have all the confirmations and I was able to find good source of sodium hydroxide and recently I found good source of aluminum. This is a duraluminum tube which I purchased in a store and it's very inexpensive (~2$), I think this volume is enough to fill a very big high-altitude balloon.

I still needed a bubbler, because the chemical reaction produce a fog which can go into the balloon and damage it or condensate on the walls of the balloon and reduce a lift. Also I was a little bit worried about the speed of the reaction and I think I need an option to attach two reaction chambers to the bubbler.

So, here it is - a new bubbler with ability to easily attach or detach a couple of reaction chambers even during the process. I've made it using a can, a garden irrigation fittings and a plastic valve for the hydrogen output.


Sorry for bad photo quality, I'll do better pictures later. On the left one you can see that the valve is opened for the attached chamber, left valve is closed because there is no chamber attached to it.

So, stay tuned, I'll update you with the test results.


вторник, 6 августа 2013 г.

Installing SQL Server Reporting Services on Windows Server Core

Hi All,

A quick post on the subject. I was searching for a while trying to understand why Microsoft limited the ability to install SRS on Server Core. I think mostly because of the fact that you actually need a web browser to work with it, in the configuration tool there are links which should be opened in a webbrowser - which is not installed on the server core.

However there are absolutely no technical limitations whatsoever for running SRS on the core. And I was able to finally find a way to install SRS on it.

A fellow familiar with the setup and how it works(thanks a lot if you are reading it!) helped me identify the name of the check which should be disabled.

So, first of all you should launch the GUI version of SQL server setup. For me it worked correctly only when I launch it from the command prompt and only when I installed GUI management tools feature, here is how you can do this (maybe everything will work even without this):

   Get-windowsfeature | ? {$_.name -like "Server-gui-mgmt*"} | install-windowsfeature

Then I installed everything using the following command

   setup.exe /action=install /features=RS /skiprules=servercoreblockunsupportedfeaturescheck    /iacceptsqlserverlicenseterms /UIMode=enableUIOnServerCore

Setup worked perfectly and now I have SQL server and SRS on Windows Server Core. Which is great!

P.S. Of course you have to have IIS already deployed on the server core and after the installation you need to launch the SRS configuration utility to create a database and web interfaces. (the tool is located at c:\ProgramData\Microsoft\Windows\StartMenu\Programs\... and then in the corresponding SQL server folder)

P.P.S. I was using SQL Server 2012 SP1.

Thanks.