Jump to content

Jack Bizon

Members
  • Posts

    11
  • Joined

  • Last visited

  1. vlad, you are right. Letting anyone mess with API would be silly. But this authentication should be handled in PHP itself. You can bring MySQL, rolling codes, encryption and so on into the game. I see many layers in "Controlling lamp over internet". First is to create connection from App to HW, then create library that handles this connection, after that build app using this library and finally add some sort of authentication.
  2. Hi Bernie, that is great and secure idea! I thought about it but I'm not a big fan of bash so i discarded this idea before even trying. However your way is seems to be the right and correct way.
  3. You are totally right but what I ment with that sentence is that cubie will not be accessible from outside world and also that I do not care about security because I know that allowing PHP itself to do sudo is also huge security risk. All this is security bomb and more like proof of concept. Many security aware people maybe will have a bit of hair loss. We could have really deep description about security of this kind of application, but that is different story. I did that...
  4. Hi everyone! I was asked by tkaiser to share something about my PHP control of GPIO pins. I can tell you that I will be happy to do so. Mostly because I'm really extremly good in one thing and that is forgetting how i did something. Now let's cut bulls**t down and start with small introduction of what I'm up to. I'll decsribe what I'm doing and what is working for me so it should all click together as project documentation and tutorial. Also all I'm going to describe is being done on Cubieboard2 (A20) but i guess that it can work almost on any ARM SBC running Debian or Ubuntu. Introduction / Motivation Basically, I'm really interested in connecting low-level hardware to high-level software applications. Why? Why throw some rellays on 8-bit atmega, connect the whole contraption to internet and control your lamp from wherever in the world? Well... because we can and also why not! So with this mindset, all that Raspberry Pi hype and working atmega contraption on my table I decided to buy Cubieboard2 back in 2013. Aaaand it was the most stupid thing I could do. Support absolute zero,community non-existent and bootable images were unusable. But it was nice dust collector running Android! Long story short, few weeks ago I came across Armbian, saw how active and supported it is and how it spans over multiple boards. Bingo, this is what I need for doing another cool thing. Standalone internet connected GPIO device that could be used by multiple devices / apps without any special driver or communication protocol and whatever else. Project description Whole idea is that Cubieboard will run webserver with PHP application. This application will provide API that will allow GPIO control using http protocol and GET requests. Security here is not a concern as all of this will be hidden behind NAT in secured private LAN. Preparations Let's assume that you have clean install of Armbian 5.0 with Legacy kernel 3.4.110 running on your A10 or A20 board. Very first thing to do is to decide how many GPIO pins and which one you want to use. Most if not all pins that you have physically availible have more than one function. UART, eMMC, SPI, I2C, LCD and many other connections. Basically you need to look into documentation of your board and check if you can use your chosen pins as GPIO instead of thier original purpose. When you have this solved you need to modify script.bin located in /boot. I will take this short way. Take script.bin, convert it to fex using sunxi-tool bin2fex, add your chosen pins into [gpio_para] section, convert modified fex back into bin, put it back to /boot, reboot board. More about this can be found here. After you prepared your pins in script.bin it's about time to get things rolling. I recommend to run first this two commands if your install is as clean as holy water apt-get update apt-get upgrade Apache and PHP5 installation This is easy step as we do not need any configuration and defaults will do just fine. Execute following command apt-get install apache2 php5 FTP server instalation (optional) This is optional but will help with uploading php files to board. First install ProFTPd as standalone server. apt-get install proftpd Now we need to configure ftp server. I will save you labor, config you need is attached just replace original one in /etc/proftpd/proftpd.conf with it. After you replace config restart proftpd service proftpd restart Next you need to create FTP account that will be used for connection to board via FTP. First lets create group named ftpgroup addgroup ftpgroup Now we add user and add it to the ftpgroup adduser ftpuser -shell /bin/false -home /var/www/html adduser ftpuser ftpgroup And last thing is to make this ftpuser owner of /var/www/html chown -R ftpuser:ftpgroup /var/www/html Done. FTP is working now and you can connect and upload PHP files via Total Commander or similar file manager. Link GPIO to web directory If we want control GPIO from PHP we need to make GPIO accessible from web directory. Therefore we have to create symlink from our web directory to GPIO folder ln -s /sys/class/gpio /var/www/html/gpio Setting permissions Now we need to set permissions to allow our PHP scripts access GPIO in full scale. Let's start with exporting and unexporting pins from PHP. To do so user www-data have to be able to write into /sys/class/gpio/export and /sys/class/gpio/unexport. We can achieve this by making www-data sudoer. Run this command visudo and in section # User priviledge specification add following line under line with root www-data ALL=NOPASSWD: ALL Save and exit. Accessing GPIO pins from PHP Here is example code how to access GPIO pin from PHP. shell_exec("sudo bash -c 'echo 37 > gpio/export'"); shell_exec("sudo bash -c 'echo out > gpio/gpio37/direction'"); shell_exec("sudo bash -c 'echo 1 > gpio/gpio37/value'"); That's all for today. If you are interested I can also write up something about PHP library itself and API possibly too. new_proftpd.zip
  5. Well, So after some experiments... I have only one SD card that I can use for experiments right now, so I will test another SD card later. However results are: Armbian 4.5 boots nicely on first try and no problems. Armbian 5.0 and 5.04 crashes on <6>axp20_ldo2: 1800 <--> 3300 mV at 3000 mV and normally boots only after boot into android from NAND and then shutdown. When i leave board without power for a while after successfull boot (3 mins are enough) then I have to boot to Android again. I even switched power adapter from 5V 850mA for 5V 2A and issue persists so power is not the problem. That leaves me with bad SD card or some bug in armbian.
  6. Is there any update about this issue? I'm having same problem with my A20 cubieboard, but workaround is to boot Android from NAND, shutdown and then Debian Jessie from SD card ad everything is OK. I would like to put Jessie into NAND but with this bug I'm afraid that this could appear on NAND and brick board. Thanks for info.
  7. Quick comparison of [gpio_para] sections from FEX file in text diff tool and verdict is: Cubieboard1 and Cubieboard2 two are absolutely the same. Cubietruck is almost the same, difference is in just two pins. gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH10<0><default><default><0> ;gpio_pin_1 = port:PG03<1><default><default><1> ;gpio_pin_2 = port:PB19<1><default><default><1> This is the difference. PG03 and PB19 are commented and PH20 and PH10 are used instead. Don't know why however, i can't get my hands on cubietruck. All in all my change can be used for Cubie1 and 2 without any problems and for cubietruck.. well you can see it up ^ ^... just two pins. About the tutorial... I'm thinking the same because it is easy to forget. I'll dive into some detailed how-to during this week or upcoming weekend but little spoiler right now. 1) start with clean armbian install 2) get apache and php working 3) setup FTP access into /var/www/html for sake of convenience 4) create symlink from /var/www/html/gpio into /sys/class/gpio 5) allow user www-data to read/write in /sys/devices/platform/gpio (chmod -R 777 /sys if you are extremely lazy) Now from /var/www/html PHP scripts should be able to set value on GPIO pins using path gpip/gpio<pin_number>/value . More detailed step by step guide is coming.
  8. I will be happy to do so! However this is maybe quite specific for cubieboard1/2. I used this Cubian fex https://github.com/mmplayer/sunxi-boards/blob/master/sys_config/a20/cubieboard2_argon.fexand took whole section [gpio_para] and matched it to armbian fex from here https://github.com/igorpecovnik/lib/blob/master/config/cubieboard2.fex. If we take a look onto section [gpio_para] the in armbian there is only this [gpio_para] gpio_used = 1 gpio_num = 2 gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH21<1><default><default><1> but in cubian we can see this [gpio_para] gpio_used = 1 gpio_num = 67 gpio_pin_1 = port:PG03<1><default><default><1> gpio_pin_2 = port:PB19<1><default><default><1> gpio_pin_3 = port:PB18<1><default><default><1> gpio_pin_4 = port:PG06<1><default><default><1> gpio_pin_5 = port:PG05<1><default><default><1> gpio_pin_6 = port:PG04<1><default><default><1> gpio_pin_7 = port:PG01<1><default><default><1> gpio_pin_8 = port:PG02<1><default><default><1> gpio_pin_9 = port:PG00<1><default><default><1> gpio_pin_10 = port:PH14<1><default><default><1> gpio_pin_11 = port:PH15<1><default><default><1> gpio_pin_12 = port:PI06<1><default><default><1> gpio_pin_13 = port:PI05<1><default><default><1> gpio_pin_14 = port:PI04<1><default><default><1> gpio_pin_15 = port:PG11<1><default><default><1> gpio_pin_16 = port:PG10<1><default><default><1> gpio_pin_17 = port:PG09<1><default><default><1> gpio_pin_18 = port:PG08<1><default><default><1> gpio_pin_19 = port:PG07<1><default><default><1> gpio_pin_20 = port:PE08<1><default><default><1> gpio_pin_21 = port:PE07<1><default><default><1> gpio_pin_22 = port:PE06<1><default><default><1> gpio_pin_23 = port:PE05<1><default><default><1> gpio_pin_24 = port:PE04<1><default><default><1> gpio_pin_25 = port:PI09<1><default><default><1> gpio_pin_26 = port:PI08<1><default><default><1> gpio_pin_27 = port:PI07<1><default><default><1> gpio_pin_28 = port:PD04<1><default><default><1> gpio_pin_29 = port:PD03<1><default><default><1> gpio_pin_30 = port:PD02<1><default><default><1> gpio_pin_31 = port:PD01<1><default><default><1> gpio_pin_32 = port:PD00<1><default><default><1> gpio_pin_33 = port:PE11<1><default><default><1> gpio_pin_34 = port:PE10<1><default><default><1> gpio_pin_35 = port:PE09<1><default><default><1> gpio_pin_36 = port:PD12<1><default><default><1> gpio_pin_37 = port:PD11<1><default><default><1> gpio_pin_38 = port:PD10<1><default><default><1> gpio_pin_39 = port:PD09<1><default><default><1> gpio_pin_40 = port:PD08<1><default><default><1> gpio_pin_41 = port:PD07<1><default><default><1> gpio_pin_42 = port:PD06<1><default><default><1> gpio_pin_43 = port:PD05<1><default><default><1> gpio_pin_44 = port:PD20<1><default><default><1> gpio_pin_45 = port:PD19<1><default><default><1> gpio_pin_46 = port:PD18<1><default><default><1> gpio_pin_47 = port:PD17<1><default><default><1> gpio_pin_48 = port:PD16<1><default><default><1> gpio_pin_49 = port:PD15<1><default><default><1> gpio_pin_50 = port:PD14<1><default><default><1> gpio_pin_51 = port:PD13<1><default><default><1> gpio_pin_52 = port:PB02<1><default><default><1> gpio_pin_53 = port:PD25<1><default><default><1> gpio_pin_54 = port:PD24<1><default><default><1> gpio_pin_55 = port:PD26<1><default><default><1> gpio_pin_56 = port:PD27<1><default><default><1> gpio_pin_57 = port:PD23<1><default><default><1> gpio_pin_58 = port:PD22<1><default><default><1> gpio_pin_59 = port:PD21<1><default><default><1> gpio_pin_60 = port:PI11<1><default><default><1> gpio_pin_61 = port:PI13<1><default><default><1> gpio_pin_62 = port:PI10<1><default><default><1> gpio_pin_63 = port:PI12<1><default><default><1> gpio_pin_64 = port:PB13<1><default><default><1> gpio_pin_65 = port:PB11<1><default><default><1> gpio_pin_66 = port:PB10<1><default><default><1> gpio_pin_67 = port:PH07<1><default><default><1> On cubieboard there is 67 gpio pins that we can use any way we want. The whole magic was to offset cubian [gpio_para] section by factor of 2 and add it to armbian fex. So the result looks like [gpio_para] gpio_used = 1 gpio_num = 69 gpio_pin_1 = port:PH20<1><default><default><1> gpio_pin_2 = port:PH21<1><default><default><1> gpio_pin_3 = port:PG03<1><default><default><1> gpio_pin_4 = port:PB19<1><default><default><1> gpio_pin_5 = port:PB18<1><default><default><1> gpio_pin_6 = port:PG06<1><default><default><1> gpio_pin_7 = port:PG05<1><default><default><1> gpio_pin_8 = port:PG04<1><default><default><1> gpio_pin_9 = port:PG01<1><default><default><1> gpio_pin_10 = port:PG02<1><default><default><1> gpio_pin_11 = port:PG00<1><default><default><1> gpio_pin_12 = port:PH14<1><default><default><1> gpio_pin_13 = port:PH15<1><default><default><1> gpio_pin_14 = port:PI06<1><default><default><1> gpio_pin_15 = port:PI05<1><default><default><1> gpio_pin_16 = port:PI04<1><default><default><1> gpio_pin_17 = port:PG11<1><default><default><1> gpio_pin_18 = port:PG10<1><default><default><1> gpio_pin_19 = port:PG09<1><default><default><1> gpio_pin_20 = port:PG08<1><default><default><1> gpio_pin_21 = port:PG07<1><default><default><1> gpio_pin_22 = port:PE08<1><default><default><1> gpio_pin_23 = port:PE07<1><default><default><1> gpio_pin_24 = port:PE06<1><default><default><1> gpio_pin_25 = port:PE05<1><default><default><1> gpio_pin_26 = port:PE04<1><default><default><1> gpio_pin_27 = port:PI09<1><default><default><1> gpio_pin_28 = port:PI08<1><default><default><1> gpio_pin_29 = port:PI07<1><default><default><1> gpio_pin_30 = port:PD04<1><default><default><1> gpio_pin_31 = port:PD03<1><default><default><1> gpio_pin_32 = port:PD02<1><default><default><1> gpio_pin_33 = port:PD01<1><default><default><1> gpio_pin_34 = port:PD00<1><default><default><1> gpio_pin_35 = port:PE11<1><default><default><1> gpio_pin_36 = port:PE10<1><default><default><1> gpio_pin_37 = port:PE09<1><default><default><1> gpio_pin_38 = port:PD12<1><default><default><1> gpio_pin_39 = port:PD11<1><default><default><1> gpio_pin_40 = port:PD10<1><default><default><1> gpio_pin_41 = port:PD09<1><default><default><1> gpio_pin_42 = port:PD08<1><default><default><1> gpio_pin_43 = port:PD07<1><default><default><1> gpio_pin_44 = port:PD06<1><default><default><1> gpio_pin_45 = port:PD05<1><default><default><1> gpio_pin_46 = port:PD20<1><default><default><1> gpio_pin_47 = port:PD19<1><default><default><1> gpio_pin_48 = port:PD18<1><default><default><1> gpio_pin_49 = port:PD17<1><default><default><1> gpio_pin_50 = port:PD16<1><default><default><1> gpio_pin_51 = port:PD15<1><default><default><1> gpio_pin_52 = port:PD14<1><default><default><1> gpio_pin_53 = port:PD13<1><default><default><1> gpio_pin_54 = port:PB02<1><default><default><1> gpio_pin_55 = port:PD25<1><default><default><1> gpio_pin_56 = port:PD24<1><default><default><1> gpio_pin_57 = port:PD26<1><default><default><1> gpio_pin_58 = port:PD27<1><default><default><1> gpio_pin_59 = port:PD23<1><default><default><1> gpio_pin_60 = port:PD22<1><default><default><1> gpio_pin_61 = port:PD21<1><default><default><1> gpio_pin_62 = port:PI11<1><default><default><1> gpio_pin_63 = port:PI13<1><default><default><1> gpio_pin_64 = port:PI10<1><default><default><1> gpio_pin_65 = port:PI12<1><default><default><1> gpio_pin_66 = port:PB13<1><default><default><1> gpio_pin_67 = port:PB11<1><default><default><1> gpio_pin_68 = port:PB10<1><default><default><1> gpio_pin_69 = port:PH07<1><default><default><1> And this way i got access to GPIO pins on my Cubieboard2. Then it was fun and games to get running my PHP app that provides API for control of GPIO pins over internet via GET requests. As you can see really simple change. I think it would be fine to include change like this in distro but as my understanding goes, armbian is about being universal and this is pretty specific for A10 and A20 boards
  9. I tought it have to do something with kernel. As I need 3.4 kernel, then I had to modify script.bin. I took script.bin from Cubian and from Armbian, merged gpio_para sections together and voilà ... GPIO works nicely on armbian same way as on cubian. I need to do some minor tweaks but I can migrate app to armbian in matter of minutes now. Thanks for your help guys!
  10. Thanks for your reply Igor. Well I'm trying PE9 and that gives me (5-1)*32+9=4*32+9=128+9=137, so then I try but that gives me If i try with 1 instead of 137 everything is OK. I tried all possible variants of echo, tee, pipelining commands but I still get the invalid argument error on exporting everything else than 1 and 2. I'm not a linux pro, more like newbie, so i guess it's something stupid. And also, I'm connected through serial line console using PL2303. Could that play any role? Thanks for reply.
  11. Hi everyone, I need to ask about GPIO pins. I have Cubieboard2 with Armbian (Jessie, Legacy) and I cannot export any GPIO pin as described here http://linux-sunxi.org/GPIO#Accessing_the_GPIO_pins_through_sysfs_with_mainline_kernel, chapter " Accessing the GPIO pins through sysfs with mainline kernel". I was able to play with GPIO this way on Cubian nicely but since Cubian is more or less dead without much support I moved to Armbian. I am able to export only pins with adress 1 or 2 as these are in the script.bin. I quite suspect that I need to change script.fex from GIT, convert to script.bin and replace original one on my Cubieboard. Am I correct? And next thing is that I do not understand what this thingy on sunxi-wiki means: "Device Drivers ---> GPIO Support ---> /sys/class/gpio/... (sysfs interface)" and how to achieve it. Thanks much for help!
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines