You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
11 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. <!-- vim-markdown-toc GFM -->
  2. * [Introduction](#introduction)
  3. * [Part-1: Introduction to IoT systems and single-board computers (SBC)](#part-1-introduction-to-iot-systems-and-single-board-computers-sbc)
  4. * [Accessing to SBCs by USB](#accessing-to-sbcs-by-usb)
  5. * [Accessing the RPi4 by ssh](#accessing-the-rpi4-by-ssh)
  6. * [Error connection](#error-connection)
  7. * [Basic commands on the Bash](#basic-commands-on-the-bash)
  8. * [Basic configuration](#basic-configuration)
  9. * [Updating the system and installing VIM](#updating-the-system-and-installing-vim)
  10. * [Changing the bb's or rpi4's hostname](#changing-the-bbs-or-rpi4s--hostname)
  11. * [Changing the user's password](#changing-the-users-password)
  12. * [Time and internet access](#time-and-internet-access)
  13. * [Oh My Bash](#oh-my-bash)
  14. * [SSH Key pairs](#ssh-key-pairs)
  15. * [Starting with the ESP32](#starting-with-the-esp32)
  16. * [Git](#git)
  17. <!-- vim-markdown-toc -->
  18. # Introduction
  19. This repository is developed to cover the embedded systems lecture at summer school in Jade University.
  20. # Part-1: Introduction to IoT systems and single-board computers (SBC)
  21. ## Accessing to SBCs by USB
  22. To connect into the SBC, attach the USB cable into the PC. Then, open the terminal and type:
  23. ```
  24. $ ip addr
  25. ...
  26. ...
  27. en10: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
  28. ether f4:5e:ab:50:44:89
  29. inet6 fe80::10a6:8287:252f:1a43/64 secured scopeid 0x16
  30. inet 192.168.6.1/24 brd 192.168.6.255 en10
  31. ...
  32. ```
  33. you will obtain a lot of `enX` or `awdlx` devices, try to search for the new detected devices and specially the one with the ip 192.168.6.1 or 192.168.7.1 that belongs to the BeagleBone devices, and XXX for the Raspberry Pi.
  34. Then, use the `SSH` protocol, from now ssh, to access the board computer (please change the ip address by your ip device)
  35. ```
  36. $ ssh debian@192.168.6.2
  37. Debian GNU/Linux 10
  38. BeagleBoard.org Debian Buster IoT Image 2022-07-01
  39. Support: https://bbb.io/debian
  40. default username:password is [debian:temppwd]
  41. The programs included with the Debian GNU/Linux system are free software;
  42. the exact distribution terms for each program are described in the
  43. individual files in /usr/share/doc/*/copyright.
  44. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
  45. permitted by applicable law.
  46. Last login: Thu Jul 7 07:08:40 2022 from 2806:2f0:5040:8572:7d51:e754:675:cd2a
  47. ```
  48. ## Accessing the RPi4 by ssh
  49. The SBCs can be accessed by ssh protocol if it is enable (disable by default at raspberry). Thus, we only need to know the SBC's ip or hostname. By default the raspberry Pi 4 is `raspberry`, but username and password is defined by the user ([raspberry Pi imager](link)). Then, to make `ssh` use:
  50. ```
  51. $ ssh username@hostname.local
  52. ```
  53. or
  54. ```
  55. $ ssh username@ip
  56. ```
  57. ## Error connection
  58. When getting the error:
  59. ```
  60. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  61. @ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
  62. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  63. The ECDSA host key for beaglebone.local has changed,
  64. and the key for the corresponding IP address 2806:103e:5:50f4:3ad2:69ff:fef9:46b4
  65. ```
  66. you have to edit the '.ssh/known_hosts' file, and delete the lien that contains the offending key and the corresponding IP address given the warning.
  67. ## Basic commands on the Bash ##
  68. Next are listing the most used and common commands on the bash-shell:
  69. - `ls`
  70. - `touch`
  71. - `rm`
  72. - `mkdir`
  73. - `cd`
  74. - `cp`
  75. let us play a little bit on bash.
  76. ## Basic configuration
  77. Once you are able to connect or get in into the SBC, a basic configuration and package installation is required. The next section will guide you install Vim, the SBC's hostname, the user password, internet access and time, and finally to install a useful bash tool.
  78. ### Updating the system and installing VIM
  79. Before any further change, please update the system and packages by:
  80. ```
  81. $ sudo apt update
  82. [sudo] password for debian:
  83. Hit:1 http://deb.debian.org/debian buster InRelease
  84. Hit:2 http://deb.debian.org/debian buster-updates InRelease
  85. Hit:3 http://security.debian.org/debian-security buster/updates InRelease
  86. Hit:4 http://repos.rcn-ee.com/debian buster InRelease
  87. Reading package lists... Done
  88. Building dependency tree
  89. Reading state information... Done
  90. 17 packages can be upgraded. Run 'apt list --upgradable' to see them.
  91. $ sudo apt list --upgradable
  92. Listing... Done
  93. bb-customizations/unknown 1.20220705.6-0~buster+20220705 all [upgradable from: 1.20220513.0-0~buster+20220513]
  94. bbb.io-kernel-4.19-ti/unknown 1.20220705.0-0~buster+20220705 all [upgradable from: 1.20220628.0-0~buster+20220628]
  95. bbb.io-kernel-tasks/unknown 1.20220705.0-0~buster+20220705 all [upgradable from: 1.20220628.0-0~buster+20220628]
  96. dirmngr/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  97. gnupg-l10n/oldstable 2.2.12-1+deb10u2 all [upgradable from: 2.2.12-1+deb10u1]
  98. gnupg-utils/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  99. gnupg/oldstable 2.2.12-1+deb10u2 all [upgradable from: 2.2.12-1+deb10u1]
  100. gpg-agent/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  101. gpg-wks-client/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  102. gpg-wks-server/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  103. gpg/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  104. gpgconf/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  105. gpgsm/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  106. gpgv/oldstable 2.2.12-1+deb10u2 armhf [upgradable from: 2.2.12-1+deb10u1]
  107. libcpupower1/oldstable 4.19.249-2 armhf [upgradable from: 4.19.235-1]
  108. linux-cpupower/oldstable 4.19.249-2 armhf [upgradable from: 4.19.235-1]
  109. linux-libc-dev/oldstable 4.19.249-2 armhf [upgradable from: 4.19.235-1]
  110. ```
  111. and then, make the upgrade of all required packages
  112. ```
  113. $ sudo apt upgrade
  114. Reading package lists... Done
  115. Building dependency tree
  116. Reading state information... Done
  117. Calculating upgrade... Done
  118. The following packages will be upgraded:
  119. bb-customizations bbb.io-kernel-4.19-ti bbb.io-kernel-tasks dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent
  120. gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv libcpupower1 linux-cpupower linux-libc-dev
  121. 17 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
  122. Need to get 9908 kB of archives.
  123. After this operation, 69.6 kB of additional disk space will be used.
  124. Do you want to continue? [Y/n] Y
  125. ...
  126. ...
  127. ...
  128. ```
  129. now we can start to install updated packages, lets try to install the `VIM` package to use as our main source and text editor:
  130. ```
  131. $ sudo apt install vim
  132. Reading package lists... Done
  133. Building dependency tree... Done
  134. Reading state information... Done
  135. The following additional packages will be installed:
  136. libgpm2 vim-runtime
  137. Suggested packages:
  138. gpm ctags vim-doc vim-scripts
  139. The following NEW packages will be installed:
  140. libgpm2 vim vim-runtime
  141. 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
  142. Need to get 7650 kB of archives.
  143. After this operation, 36.4 MB of additional disk space will be used.
  144. Do you want to continue? [Y/n] y
  145. Get:1 http://deb.debian.org/debian bullseye/main arm64 libgpm2 arm64 1.20.7-8 [35.9 kB]
  146. Get:2 http://deb.debian.org/debian bullseye/main arm64 vim-runtime all 2:8.2.2434-3+deb11u1 [6226 kB]
  147. Get:3 http://deb.debian.org/debian bullseye/main arm64 vim arm64 2:8.2.2434-3+deb11u1 [1388 kB]
  148. Fetched 7650 kB in 0s (17.0 MB/s)
  149. perl: warning: Setting locale failed.
  150. perl: warning: Please check that your locale settings:
  151. LANGUAGE = (unset),
  152. LC_ALL = (unset),
  153. LC_CTYPE = "UTF-8",
  154. LANG = "en_GB.UTF-8"
  155. are supported and installed on your system.
  156. perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").
  157. .
  158. .
  159. .
  160. ```
  161. ### Changing the bb's or rpi4's hostname
  162. First edit the `/etc/hostname` file by:
  163. ```
  164. $ sudo vim /etc/hostname
  165. ```
  166. change the first and only line in this file to reflect your new hostname.
  167. Then, edit the `/etc/hosts` file:
  168. ```
  169. 127.0.0.1 localhost
  170. 127.0.1.1 hostname.localdomain hostname
  171. # The following lines are desirable for IPv6 capable hosts
  172. ::1 localhost ip6-localhost ip6-loopback
  173. ff02::1 ip6-allnodes
  174. ff02::2 ip6-allrouters
  175. ```
  176. change the second line in both `hostname` (127.0.1.1) instances for your new hostanme (must be the same previously defined).
  177. Finally, reboot your beagle or raspberry device.
  178. ### Changing the user's password
  179. To change the default user's password use:
  180. ```
  181. $ passwd
  182. Changing password for debian.
  183. Current password: temppwd
  184. New password: xxxxxxx
  185. ...
  186. ```
  187. ### Time and internet access
  188. We previously have checked the internet access to our SBC-devices, now, let us use the internet to sync our time zone and locales for the further sync of commits in the git system. Thus, let us check the time at the device by:
  189. ```
  190. $ systemctl status time-sync.target
  191. time-sync.target - System Time Synchronized
  192. Loaded: loaded (/lib/systemd/system/time-sync.target; static; vendor preset: enabled)
  193. Active: active since Wed 2022-07-06 22:06:43 CDT; 14min ago
  194. Docs: man:systemd.special(7)
  195. ```
  196. if time is wrong use the next command and follow the instructions:
  197. ```
  198. $ sudo dpkg-reconfigure tzdata
  199. ```
  200. the, the system will have the correct time now.
  201. If locale settings fail use:
  202. ```
  203. $ sudo dpkg-reconfigure locales
  204. ```
  205. and choose your desired locales, it is recommended to use international english with UTF-8 compatibility.
  206. ### Oh My Bash
  207. Next, to make easier work with the bash system let us install the oh-my-bash tool:
  208. ```
  209. $ bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"
  210. ```
  211. you can go deeper and customize the themes and plugins at [oh-my-bash](https://ohmybash.nntoan.com/)
  212. ## SSH Key pairs
  213. To create key pairs use:
  214. ```
  215. $ ssh-keygen -t ed25519 -C "your_email@example.com"
  216. ...
  217. ...
  218. ...
  219. ```
  220. then copy the `*.pub` file generated:
  221. ```
  222. $ ssh-copy-id -i ~/.ssh/id_ed25519.pub debian@bbb-marx.local
  223. /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/gmarx/.ssh/id_ed25519.pub"
  224. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
  225. /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
  226. Debian GNU/Linux 10
  227. BeagleBoard.org Debian Buster IoT Image 2022-07-01
  228. Support: https://bbb.io/debian
  229. default username:password is [debian:temppwd]
  230. debian@bbb-marx.local's password:
  231. Number of key(s) added: 1
  232. Now try logging into the machine, with: "ssh 'debian@bbb-marx.local'"
  233. and check to make sure that only the key(s) you wanted were added.
  234. ```
  235. # Starting with the ESP32 #
  236. The next section will introduce the basics of programming the ESP32 with the Arduino IDE. The first codes allow us to use the GPIOs, serial communication, Wi-Fi, and finally the MQTT protocol.
  237. Nevertheless, some basics of Git *Control Version System* is required before start.
  238. ## Git
  239. Git is a system for version controller developed by Linus Torvalds in 2005 for developing the Linux Kernel.
  240. Then, you can specify Git configuration settings with the git config command. One of the first things you did was set up your name and email address:
  241. ```
  242. git config --global user.name "John Doe"
  243. git config --global user.email johndoe@example.com
  244. ```
  245. also you can set the main editor or client to commit:
  246. ```
  247. git config --global core.editor emacs
  248. ```
  249. Now, try to create a new repository with two files: file-a and file-b, add some lines of code, and make a commit. Next, make some changes, and only commit the changes on file-a, the changes on file-b restore them to previous commit.