{"id":600,"date":"2018-01-22T20:30:37","date_gmt":"2018-01-22T19:30:37","guid":{"rendered":"https:\/\/www.anginf.de\/?p=600"},"modified":"2018-02-15T12:56:33","modified_gmt":"2018-02-15T11:56:33","slug":"arduino-compile-on-command-line-for-esp8266-for-ci-continious-integration","status":"publish","type":"post","link":"https:\/\/www.anginf.de\/?p=600","title":{"rendered":"Arduino compile on command line for ESP8266 for CI (Continuous Integration)"},"content":{"rendered":"<p>I wanted to test the functionality of <a href=\"https:\/\/about.gitlab.com\/\" rel=\"noopener\" target=\"_blank\">GitLab<\/a> for <a href=\"https:\/\/about.gitlab.com\/features\/gitlab-ci-cd\/\" rel=\"noopener\" target=\"_blank\">CI<\/a>. As I have a lot of code which was written with the Arduino IDE for ESP8266-Boards, especially for the WeMos D1 Mini, I figured that I should try to automate the compile process for verification of the code.<\/p>\n<p>There were some minor problems that I had to work out first, though:<\/p>\n<pre lang=\"bash\">\r\n# Unpack newest Arduino IDE somewhere, e.g. \/opt\/arduino\/arduino-1.8.5 and cd to that dir\r\nmkdir \/opt\/arduino\r\ncd \/opt\/arduino\r\nwget https:\/\/downloads.arduino.cc\/arduino-1.8.5-linux64.tar.xz\r\ntar xvfJ arduino-1.8.5-linux64.tar.xz\r\ncd arduino-1.8.5\r\n<\/pre>\n<p>The further configuration MUST be made under the new user &#8222;gitlab-runner&#8220;, as this context will be used during the CI. So we have to create the user first and switch into his context:<\/p>\n<pre lang=\"bash\">\r\nsudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell \/bin\/bash\r\nsudo su - gitlab-runner\r\n<\/pre>\n<p>Make sure that the current user is now the gitlab-runner, than continue:<\/p>\n<pre lang=\"bash\">\r\n# Add Additional Boards (ESP8266)\r\ncd \/opt\/arduino\/arduino-1.8.5\r\n.\/arduino --pref \"boardsmanager.additional.urls=https:\/\/adafruit.github.io\/arduino-board-index\/package_adafruit_index.json,http:\/\/arduino.esp8266.com\/stable\/package_esp8266com_index.json\" --save-prefs\r\n.\/arduino --install-boards esp8266:esp8266\r\n<\/pre>\n<p>The resulting board specifications can be found here:<br \/>\n<code>~\/.arduino15\/packages\/esp8266\/hardware\/esp8266\/2.4.0\/boards.txt<\/code><\/p>\n<p>Some libraries can be installed easily as they are available directly from the official library list, these can be installed like this:<\/p>\n<pre lang=\"bash\">\r\n# Install SimpleDHT\r\n.\/arduino --install-library SimpleDHT\r\n<\/pre>\n<p>Than there are some libraries, preferably on github, which are available as a tar.gz-File, these should be installed to the <code>~\/Arduino\/libraries<\/code>-Directory, like this (for AsyncMQTTClient):<\/p>\n<pre lang=\"bash\">\r\n# Install AsyncMQTTClient\r\nwget -q https:\/\/github.com\/marvinroger\/async-mqtt-client\/archive\/v0.8.1.tar.gz -O - | tar xvfz - -C ~\/Arduino\/libraries\/\r\n<\/pre>\n<p>The above mentioned Library depends on ESPAsyncTCP, which is NOT available as a ZIP-File, so we have to clone the github directory and copy the relevant part to the Library-Directory:<\/p>\n<pre lang=\"bash\">\r\n# Install ESPAsyncTCP\r\nGITCLONEDIR=$(mktemp -d) && git clone https:\/\/github.com\/me-no-dev\/ESPAsyncTCP ${GITCLONEDIR} && cp -r ${GITCLONEDIR}\/src ~\/Arduino\/libraries\/ESPAsyncTCP\r\n<\/pre>\n<p>To test compilation, we&#8217;ll be using the following short code, put it in a directory &#8222;ESP-TEST&#8220; and name it &#8222;ESP-TEST.ino&#8220;:<\/p>\n<pre lang=\"c\">\r\n#include <ESP8266WiFi.h>\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  Serial.println(\"5s Deep Sleep initiating\");\r\n  ESP.deepSleep(5000000);\r\n  delay(100);\r\n}\r\n\r\nvoid loop() {}\r\n<\/pre>\n<p>To run the compilation, we have to set the CPU Frequency (here: 80 MHz) and the Memory Ratio on how much we want to give to SPIFFS (here: 1M for SPIFFS):<\/p>\n<pre lang=\"bash\">\r\n.\/arduino -v --board esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M1M --verify ESP-TEST\/ESP-TEST.ino\r\n<\/pre>\n<p>To activate the CI in GitLab, we first have to install the gitlab-runner as a service. Trouble is, the gitlab-runner which is available from within Ubuntu (17.10 as of the time of this writing) is <a href=\"https:\/\/forum.gitlab.com\/t\/error-registering-runner-failed-runner-38buk9-k-status-404-not-found\/6584\/11\" rel=\"noopener\" target=\"_blank\">incompatible with gitlab >10.0<\/a>, so we MUST install it manually as mentioned on the <a href=\"https:\/\/docs.gitlab.com\/runner\/install\/linux-manually.html\" rel=\"noopener\" target=\"_blank\">GitLab Runner Install Site<\/a>.<\/p>\n<pre lang=\"bash\">\r\nsudo wget -O \/usr\/local\/bin\/gitlab-runner https:\/\/gitlab-runner-downloads.s3.amazonaws.com\/latest\/binaries\/gitlab-runner-linux-amd64\r\nsudo chmod +x \/usr\/local\/bin\/gitlab-runner\r\nsudo \/usr\/local\/bin\/gitlab-runner install --user=gitlab-runner --working-directory=\/home\/gitlab-runner\r\nsudo gitlab-runner start\r\n<\/pre>\n<p>For updates of the runner in the future, you have to follow these instructions:<\/p>\n<pre lang=\"bash\">\r\nsudo gitlab-runner stop\r\nsudo wget -O \/usr\/local\/bin\/gitlab-runner https:\/\/gitlab-runner-downloads.s3.amazonaws.com\/latest\/binaries\/gitlab-runner-linux-amd64\r\nsudo chmod +x \/usr\/local\/bin\/gitlab-runner\r\nsudo gitlab-runner start\r\n<\/pre>\n<p>In your GitLab Project-Settings, go to &#8222;CI\/CD&#8220; and use the values under &#8222;Specific Runners&#8220; to register the runner. When asked for a executor, answer &#8222;Shell&#8220;. Please activate &#8222;git clone&#8220; instead of &#8222;git fetch&#8220;, at least in my configuration I got errors like <code>error: could not lock config file<\/code>, the switch to &#8222;git clone&#8220; resolved these.<\/p>\n<pre lang=\"bash\">\r\nsudo gitlab-runner register\r\n<\/pre>\n<p>By now the runner should be registered, but we still have to &#8222;run&#8220; it. I prefer using a <code>screen<\/code> session for this. Exit the session by pressing CTRL+a and then &#8222;d&#8220; (this &#8222;detaches the screen&#8220;, to return to the screen, enter <code>screen -r gitlabrunner<\/code>).<\/p>\n<pre lang=\"bash\">\r\nscreen -S gitlabrunner\r\ncd ~gitlab-runner\r\nsudo gitlab-runner run --user=gitlab-runner\r\n# Exit by pressing \"CTRL+a\" and then \"d\".\r\n<\/pre>\n<p>Finally we can start with the <code>.gitlab-ci.yml<\/code>. Add a file with this name to your project and add the following context (assuming you were using the example project from above):<\/p>\n<pre lang=\"yaml\">\r\nbuild:\r\n  stage: build\r\n  script: \r\n  - \/opt\/arduino\/arduino-1.8.5\/arduino -v --board esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M1M --verify ESP8266-DHT22.ino\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to test the functionality of GitLab for CI. As I have a lot of code which was written with the Arduino IDE for ESP8266-Boards, especially for the WeMos D1 Mini, I figured that I should try to automate the compile process for verification of the code. There were some minor problems that I &hellip; <a href=\"https:\/\/www.anginf.de\/?p=600\" class=\"more-link\"><span class=\"screen-reader-text\">Arduino compile on command line for ESP8266 for CI (Continuous Integration)<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-600","post","type-post","status-publish","format-standard","hentry","category-esp8266"],"_links":{"self":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=600"}],"version-history":[{"count":16,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/600\/revisions"}],"predecessor-version":[{"id":618,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/600\/revisions\/618"}],"wp:attachment":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}