Показаны сообщения с ярлыком Netgear Stora. Показать все сообщения
Показаны сообщения с ярлыком Netgear Stora. Показать все сообщения

пятница, 16 января 2015 г.

Netgear Stora with connected Arduino and Zabbix

Was able to install Zabbix on my Netgear Stora device. Took some time and setup code modifications were required (because mysql is lower version in Stora as well as some php addons).

Zabbix is very usefull tool to quickly configure the monitoring and notification system with ability to check metric charts and trends and set triggers and actions.

I'm using it now to monitor the free space and overall health of the Netgear Stora device, router traffic (via SNMP) and, what is more important for me - different aspects of Arduino subsystem (I have Arduino Due connected via USB). I've created a PHP script which takes commands as parameters and returns data reported by arduino. Zabbix agent is using this script to get data from Arduino. Currently I monitor RAM usage of my Arduino system (because has a dynamic tree-like memory allocation system for data reported by remote nodes), so that I can see if my Arduino is about to kaboom :) because of too many nodes reporting to the root node or just because of firmware glitch on Arduino, illumination using the photoresistor on one of the nodes (just for testing purposes), here is the chart screenshot


Also I'm collecting number of cycles certain node is unresponsive, so that zabbix can notify me if certain node is not responding anymore. I have plans to use Zabbix way of autodiscovering new nodes and automatically monitoring them, currently I've just added 2 active node manually, here is the configuration of the Zabbix item, Arduino RAM usage in this case.


Below is a config of my zabbix agent. It should be placed as a separate .conf file into zabbix_agentd.conf.d subfolder, but before that you have to uncomment the following line in the main agentd config:

Include=/opt/usr/local/etc/zabbix_agentd.conf.d/*.conf

userparameter_arduino.conf:

UserParameter=arduino.light,/opt/bin/php -f /home/sg_parser/ardu_get.php l 1 3
UserParameter=arduino.ram,/opt/bin/php -f /home/sg_parser/ardu_get.php s 0 3
UserParameter=arduino.cycles[*],/opt/bin/php -f /home/sg_parser/ardu_get.php c $1 3

All of the paramters for ardu_get.php is just to extract the numeric part of certain node, light sensor is on the node 1 for example, while RAM is on the parent or 0 node and cycles can be gathered for any discovered node.

And now non-arduino part of using Zabbix, here is free space on my Stora, Stora CPU usage and traffic via router (using SNMP data). I'm also monitoring mysql load and apache performance.



вторник, 11 ноября 2014 г.

Uploading Arduino .hex from Netgear Stora

AAAAAAAAA

I've done it. After so much pain. I even do not remmeber all the steps. However:


  • I've compiled usb drivers and ftdi drivers. I have a post about it 
  • I've compiled avrdude 6 on my Netgear Stora. Don't ask how. There was also a lot of pain. But for some reason avrdude 6 worked while v5 still cannot be compiled.
  • I have a daemon which talks to arduino, so to program I have to switch it off
  • Then I faced an issue whatever I tried I receive "avrdude: stk500_getsync(): not in sync". Looks like the issue was with my usb and ftdi drivers - for some reasons they can't help avrdude to negotiate a correct baudrate for my arduino. I tried several and looks like 57600 worked for me. I tried terminal mode like this
/root/avrdude-6.0.1/avrdude -t -v -v -v -v -c arduino -p m328p -b 57600 -P /dev/ttyUSB0

  • But then another issue arised - looks like core version of avrdude cannot properly reset the arduino. There are several tricks on how to do that manually - I'll try them later. Also I think Arduino's version of avrdude can do that, but I have issues compiling it on my Netgear (some Perl issues - nothing too serious can be solved in the future). So I went with another solution - I just reset my USB subsystem and then attach to arduino to upload a sketch. To reset the usb subsistem I'm doing the following:

echo -n "1-0:1.0" > /sys/bus/usb/drivers/hub/unbind
echo -n "1-0:1.0" > /sys/bus/usb/drivers/hub/bind

  •  In the above code IDs of your USB hub could be different, so check them in the folder /sys/bus/usb/drivers/hub/, but I guess on all Storas they should be the same.
  • Then upload the sketch, like that:
/root/avrdude-6.0.1/avrdude -v -v -v -v -c arduino -p m328p -b 57600 -P /dev/ttyUSB0 -D -Uflash:w:/home/arduino/Firmw4_4.cpp.hex
Have a good time with your IoT ;)

вторник, 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.