{"id":209,"date":"2013-03-11T22:36:48","date_gmt":"2013-03-12T05:36:48","guid":{"rendered":"https:\/\/www.uniteng.com\/?p=209"},"modified":"2021-01-05T14:45:46","modified_gmt":"2021-01-05T06:45:46","slug":"accessing-serial-port-via-cgi-script","status":"publish","type":"post","link":"https:\/\/www.uniteng.com\/index.php\/2013\/03\/11\/accessing-serial-port-via-cgi-script\/","title":{"rendered":"Accessing serial port via CGI script"},"content":{"rendered":"<p><strong>Prerequisites:<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/www.uniteng.com\/index.php\/2012\/12\/26\/part-3-using-serial-port-on-universal-expansion-board\/\" target=\"_blank\" rel=\"noopener\">Part 3: Using Serial Port on Universal Expansion Board<\/a><\/li>\n<\/ul>\n<ul>\n<li><a href=\"https:\/\/www.uniteng.com\/index.php\/2013\/03\/11\/python-cgi-script-with-lighttpd\/\" target=\"_blank\" rel=\"noopener\">Python CGI script with lighttpd (Root privileges are required)<\/a><\/li>\n<\/ul>\n<p><strong>1. Install pyserial on RaspberryPi<\/strong><\/p>\n<ul>\na. <a href=\"http:\/\/sourceforge.net\/projects\/pyserial\/files\/pyserial\/2.5\/\" target=\"_blank\" rel=\"noopener\">Download pyserial-2.5.tar.gz (106.3 kB)<\/a><br \/>\nb. unzipping and untaring<\/p>\n<pre class=\"brush:cpp;\">gunzip pyserial-2.5.tar.gz\r\ntar -xvf pyserial-2.5.tar<\/pre>\n<p>c. Install pySerial<\/p>\n<pre class=\"brush:cpp;\">cd pyserial-2.5\r\nsudo python setup.py install\r\n<\/pre>\n<\/ul>\n<p><strong>2.Testing<\/strong><\/p>\n<ul>\nSaving following python CGI scripts to your CGI folder.<\/p>\n<p>Filename: shows.py<\/p>\n<pre class=\"brush:cpp;\">#!\/usr\/bin\/python\r\nimport os\r\nser = os.popen(\"sudo python stest.py\").readlines() \r\n# print \"Content-Type: text\/html\"\r\n# print\r\nprint ser[0]\r\nprint ser[2]<\/pre>\n<p>Filename: stest.py<\/p>\n<pre class=\"brush:cpp;\">#!\/usr\/bin\/python\r\nimport serial\r\nserialport = serial.Serial(\"\/dev\/ttyAMA0\",9600,timeout=0.5)\r\nserialport.write(\"\\r\")\r\nresponse = serialport.readlines(None)\r\nserialport.write(\"version\\r\")\r\nresponse = serialport.readlines(None)\r\n\r\nprint response[1]\r\nprint response[2]\r\n<\/pre>\n<p>The python CGI script shows.py will acquire and return the Version Information of the Shell(This shell is a part of my real time operating system) which runs on the serial port of the STM32 MCU.<br \/>\n<a href=\"https:\/\/www.uniteng.com\/wp-content\/uploads\/2013\/03\/CGIwithSerilPort1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.uniteng.com\/wp-content\/uploads\/2013\/03\/CGIwithSerilPort1.png\" alt=\"CGIwithSerilPort\" width=\"386\" height=\"120\" class=\"alignnone size-full wp-image-246\" srcset=\"https:\/\/www.uniteng.com\/wp-content\/uploads\/2013\/03\/CGIwithSerilPort1.png 386w, https:\/\/www.uniteng.com\/wp-content\/uploads\/2013\/03\/CGIwithSerilPort1-300x93.png 300w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><\/a>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites: Part 3: Using Serial Port on Universal Expansion Board Python CGI script with lighttpd (Root privileges are required) 1. Install pyserial on RaspberryPi a. Download pyserial-2.5.tar.gz (106.3 kB) b. unzipping and untaring gunzip pyserial-2.5.tar.gz tar -xvf pyserial-2.5.tar c. Install pySerial cd pyserial-2.5 sudo python setup.py install 2.Testing Saving following python CGI scripts to your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ngg_post_thumbnail":0,"footnotes":""},"categories":[5,11],"tags":[6,9,8,7],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-hardware-notes","category-software-notes","tag-raspberrypi","tag-rs232","tag-serial-port","tag-universal-expansion-board"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"neilhao","author_link":"https:\/\/www.uniteng.com\/index.php\/author\/neilhao\/"},"uagb_comment_info":0,"uagb_excerpt":"Prerequisites: Part 3: Using Serial Port on Universal Expansion Board Python CGI script with lighttpd (Root privileges are required) 1. Install pyserial on RaspberryPi a. Download pyserial-2.5.tar.gz (106.3 kB) b. unzipping and untaring gunzip pyserial-2.5.tar.gz tar -xvf pyserial-2.5.tar c. Install pySerial cd pyserial-2.5 sudo python setup.py install 2.Testing Saving following python CGI scripts to your&hellip;","_links":{"self":[{"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":0,"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.uniteng.com\/index.php\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}