{"id":263,"date":"2019-08-25T04:00:00","date_gmt":"2019-08-25T03:00:00","guid":{"rendered":"http:\/\/tescaweb.nl\/Carel\/?p=263"},"modified":"2022-01-26T14:11:53","modified_gmt":"2022-01-26T13:11:53","slug":"notes-about-the-fischertechnik-txt-firmware-version-4-5-and-higher-1","status":"publish","type":"post","link":"http:\/\/tescaweb.nl\/Carel\/?p=263","title":{"rendered":"Using TXT CivetWeb server as general web server (part 2)"},"content":{"rendered":"\n<h2 id=\"introduction\">Introduction<\/h2>\n\n\n\n<p>In this part I will show how to create a CGI. With C\/C++ and\/or with Python.<br> The C\/C++ projects need to be compiled with the same Eclipse configuration as used for the download programs an the SLI programs, see the installation section in:&nbsp;<br><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/fischertechnik\/txt_demo_c_download\/blob\/master\/README.md\" target=\"_blank\">https:\/\/github.com\/fischertechnik\/txt_demo_c_download\/blob\/master\/README.md<\/a> or<a href=\"https:\/\/github.com\/fischertechnik\/txt_demo_ROBOPro_SLI\/blob\/master\/README.md\">https:\/\/github.com\/fischertechnik\/txt_demo_ROBOPro_SLI\/blob\/master\/README.md<\/a><\/p>\n\n\n\n<h2 id=\"startpoint\">Startpoint<\/h2>\n\n\n\n<p>We have already setup a Civetweb server as we have shown in de post &#8220;Using TXT CivetWeb server as general web server (part 1A)&#8221;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 id=\"first-expriment\">First expriment<\/h2>\n\n\n\n<p>Add some files to the  document_root. And discover the CGI-script with Python or a pre-compiled C\/C++ CGI-script. <\/p>\n\n\n\n<h4 id=\"example-of-a-simple-c-c-script\">Example of a simple C\/C++ script<\/h4>\n\n\n\n<p>filenaam: cpptest.cgi, in \/var\/www, don&#8217;t forget to adjust the file attributes.<\/p>\n\n\n\n<p>This file needs to be compiled with the same Eclipse configuration as used for the download programs an the SLI programs, see the installation section in:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/fischertechnik\/txt_demo_c_download\/blob\/master\/README.md\" target=\"_blank\">https:\/\/github.com\/fischertechnik\/txt_demo_c_download\/blob\/master\/README.md<\/a><\/p>\n\n\n\n<p>Compiles the main.cpp to  TxtCgiTest01.cgi<br>Web page:   TxtCgiTest01.html<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-c++src&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot;main.cpp&quot;,&quot;language&quot;:&quot;C++&quot;,&quot;modeName&quot;:&quot;cpp&quot;}\">\/**********************************************************\n *  Compiler:   gcc \/ g++\n *\n * Simple CGI example\n *\n  **********************************************************\/\n#include &lt;stdio.h&gt;          \/\/ for printf()\n#include &lt;unistd.h&gt;         \/\/ for sleep()\n\/\/#include &quot;KeLibTxtDl.h&quot;     \/\/ TXT Lib\n\/\/#include &quot;FtShmem.h&quot;        \/\/ TXT Transfer Area\nint main(void)\n{\n     printf(&quot;Content-type: text\/html\\n\\n&quot;) ;\n     \/** Print the HTML response page to STDOUT. **\/\n     printf(&quot;&lt;html&gt;\\n&quot;) ;\n     printf(&quot;&lt;head&gt;&lt;title&gt;CGI Output&lt;\/title&gt;&lt;\/head&gt;\\n&quot;) ;\n     printf(&quot;&lt;body&gt;\\n&quot;) ;\n     printf(&quot;&lt;h1&gt;Hello, world.&lt;\/h1&gt;\\n&quot;) ;\n     printf(&quot;&lt;\/body&gt;\\n&quot;) ;\n     printf(&quot;&lt;\/html&gt;\\n&quot;) ;\n return 0;\n}<\/pre><\/div>\n\n\n\n<h2 id=\"example-of-a-simple-python-script\">Example of a simple Python script<\/h2>\n\n\n\n<p>filenaam: pytest.cgi, in \/var\/www, don&#8217;t forget to adjust the file attributes.<\/p>\n\n\n\n<p>This example make use of the already pre-installed FtRoboPy. It is also possible to use the fischertechnik C\/C+ libraries directly from a C\/C++ CGI-script. <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:false,&quot;languageLabel&quot;:&quot;file&quot;,&quot;fileName&quot;:&quot; pytest.cgi &quot;,&quot;language&quot;:&quot;Python&quot;,&quot;modeName&quot;:&quot;python&quot;}\">module#!\/usr\/bin\/python3\n# Import modules for CGI handling\nimport cgi, cgitb\nimport ftrobopy\nimport sys\nprint (&quot;Content-type:text\/html\\r\\n\\r\\n&quot;)\nprint ('&lt;html&gt;')\nprint ('&lt;head&gt;')\nprint ('&lt;title&gt;Hello Word - First CGI Program&lt;\/title&gt;')\nprint ('&lt;\/head&gt;')\nprint ('&lt;body&gt;')\nprint ('&lt;h2&gt;Hello Word! This is my first CGI program&lt;\/h2&gt;')\nprint ('&lt;p&gt;')\ntxt=ftrobopy.ftrobopy('auto')\nprint (&quot;1&lt;br\/&gt;&quot;)\ntxt.play_sound(int(1),int(0))\nprint (&quot;1A&lt;br\/&gt;&quot;)\nwhile not txt.sound_finished():   pass\nprint (&quot;2&lt;br\/&gt;&quot;)\nMotor_links  = txt.motor(2)\nprint (&quot;3&lt;br\/&gt;&quot;)\nMotor_links.setSpeed(512)\nprint (&quot;4&lt;br\/&gt;&quot;)\nMotor_links.setDistance(500, syncto=0)\nprint ('5&lt;br\/&gt;')\nwhile not Motor_links.finished():\n  print ('r')\nprint (&quot;&lt;br \/&gt;&quot;)\ntxt.stopOnline()\nprint (&quot;End FT program&lt;br\/&gt;&quot;)\nprint ('&lt;\/p&gt;')\nprint ('&lt;\/body&gt;')\nprint ('&lt;\/html&gt;')<\/pre><\/div>\n\n\n\n<p>There are more options to use the public data area as document_root for the CivetWeb server.<\/p>\n\n\n\n<ul><li>Change the document_root in a way that it point to under the user: ROBOPro accessible data area.<\/li><li>start a new instance of the CivetWeb server on a different port (8081) and  document_root in a way that it point to under the user: ROBOPro accessible data area. <\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>My notes during my work with the CivetWeb server on the fischertechnik TXT-controller<\/p>\n","protected":false},"author":1,"featured_media":549,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"categories":[12,6,11,7],"tags":[51,14,49,16,50,46,52,47,17,45],"post_folder":[],"_links":{"self":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/263"}],"collection":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263"}],"version-history":[{"count":2,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":794,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/posts\/263\/revisions\/794"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=\/wp\/v2\/media\/549"}],"wp:attachment":[{"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263"},{"taxonomy":"post_folder","embeddable":true,"href":"http:\/\/tescaweb.nl\/Carel\/index.php?rest_route=%2Fwp%2Fv2%2Fpost_folder&post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}