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.

150 lines
3.9 KiB

  1. # Things Gateway by Mozilla
  2. Build Your Own Web of Things Gateway. The "Web of Things" (WoT) is the idea of
  3. taking the lessons learned from the World Wide Web and applying them to IoT.
  4. It's about creating a decentralized Internet of Things by giving Things URLs on
  5. the web to make them linkable and discoverable, and defining a standard data
  6. model and APIs to make them interoperable.
  7. ### Getting Started
  8. These instructions will get you a copy of OpenWrt's build system on your local
  9. machine for development and testing purposes. To check the prerequisites for
  10. your system check out this
  11. [link](https://openwrt.org/docs/guide-developer/build-system/install-buildsystem).
  12. ```
  13. git clone https://github.com/openwrt/openwrt
  14. cd openwrt
  15. ```
  16. ### Configure the build system
  17. We need to configure the build system and select the Things Gateway package.
  18. This process is no different from selecting other OpenWrt packages. For this
  19. example we will be using build configuration for Raspberry Pi 2/3.
  20. Update feeds and open menuconfig interface:
  21. ```
  22. make package/symlinks
  23. make menuconfig
  24. ```
  25. Select your target:
  26. ```
  27. Target System (Broadcom BCM27xx) --->
  28. Subtarget (BCM2709/BCM2710 32 bit based boards) --->
  29. Target Profile (Raspberry Pi 2B/3B/3B+/3CM) --->
  30. ```
  31. Things Gateway package is a bit beefy. In order to fit the image, extend the
  32. filesystem size from 256 to 1024 MB:
  33. ```
  34. Target Images --->
  35. (1024) Root filesystem partition size (in MB)
  36. ```
  37. Select Things Gateway package:
  38. ```
  39. Languages --->
  40. Node.js --->
  41. <*> node-mozilla-iot-gateway
  42. ```
  43. Save and exit.
  44. ### Building the image
  45. Run the build process and substitute <N> with the number of your CPU cores:
  46. ```
  47. make -j<N>
  48. ```
  49. ### Flashing on the SD card
  50. Process of flashing the image will depend on which device you have.
  51. Instructions below are for Raspberry Pi 2/3. For other devices consult OpenWrt
  52. wiki pages. Be careful to replace the X in the third command with the drive
  53. letter of your SD card.
  54. ```
  55. cd bin/targets/brcm2708/bcm2709
  56. gunzip openwrt-brcm2708-bcm2709-rpi-2-ext4-factory.img.gz
  57. sudo dd if=openwrt-brcm2708-bcm2709-rpi-2-ext4-factory.img of=/dev/sdX conv=fsync
  58. ```
  59. ## Running Things Gateway from USB flash drive
  60. In case the device doesn't have enough internal storage space, it is possible
  61. to run Things Gateway of a USB flash drive. This requires USB flash drive with
  62. ext4 filesystem plugged in the device.
  63. ### Configuration
  64. Do all steps from "Configure the build system" above, and after that change
  65. node-mozilla-iot-gateway selection from "\*" to "M". This will build the
  66. package and all of it's dependencies but it will not install Things Gateway.
  67. ```
  68. Languages --->
  69. Node.js --->
  70. <M> node-mozilla-iot-gateway
  71. ```
  72. ### Prepare the device
  73. We need to auto mount the USB flash drive in order for the gateway to start at
  74. boot. To do so, open a console on your embedded device and create a /etc/fstab
  75. file with the following contents. This assumes your USB flash drive is
  76. /dev/sda1:
  77. ```
  78. /dev/sda1 /opt ext4 rw,relatime,data=ordered 0 1
  79. /opt/root /root none defaults,bind 0 0
  80. ```
  81. Add "mount -a" to the end of the "boot" function in /etc/init.d/boot
  82. ```
  83. boot() {
  84. .
  85. .
  86. .
  87. /bin/config_generate
  88. uci_apply_defaults
  89. # temporary hack until configd exists
  90. /sbin/reload_config
  91. # Added by us
  92. mount -a
  93. }
  94. ```
  95. ### Install Things Gateway package
  96. After successfully mounting the USB drive, transfer the .ipk file from your
  97. local machine to the device and install it. Note that your package version
  98. might defer. Also note that location of .ipk file depends on the selected
  99. target, but it will be within ./bin/packages directory. We need to use
  100. "--force-space" or else opkg might complain about insufficient space.
  101. On your local machine:
  102. ```
  103. cd bin/packages/arm_cortex-a9_vfpv3/packages/
  104. scp node-mozilla-iot-gateway_0.6.0-1_arm_cortex-a9_vfpv3.ipk root@192.168.1.1:/tmp
  105. ```
  106. On the device:
  107. ```
  108. opkg --force-space install /tmp/node-mozilla-iot-gateway_0.6.0-1_arm_cortex-a9_vfpv3.ipk
  109. ```
  110. Things Gateway should now start at every boot.