2019-02-24

    Connected Devices: Raspberry Pi ZeroW and Node.js

    👉 Source code is here

    The process of working with Raspberry Pi for the first time is an mixture of frustration and excitement.

    To set up an OS from scratch (well, not from scratch, because previous contributors have done incredibly amount of works for us) is a bit frightening. I had some experience of working servers set up in Digital Ocean and AWS cloud before, but I don't have a clear idea what was I doing for most of the time, only following instructions and putting in commands. Given another chance to deal with shell and kernel with Pi, though I'm still not feeling too comfortable input the commands to download or setup something, not so intimadated by the scripts this time.

    Challenges

    • Installing OS on SD card

    I started the installation process with Tom's image provided in class, but couldn't get access into the shell for unknown reason. In the end, I reburn the SD card with Raspbian Lite, and finally made it work.

    During the process of configuring config.txt, cmdline.txt and ssh file, I found that ssh file disappears as I check it as I read it from my computer, after I added the file into the burned SD card, injecting it into Pi, and removed it from Pi again.

    • Configuring Node.js

    I accidentally downloaded the lastest version of Node.js, which is 11.10.0, instead of stable version. This gave me trouble when I try to call node because I set the symlinks with sudo ln -s ~/.nvm/versions/node/v10.12.0/bin/node. Got resolved by reconfiguring the symlinks with lastest version.

    • Sending data to server

    I still found it a bit hard to put myself in a server-side mindset. Initially, I was thinking setting up a local server using Express.js like we did before, and somehow sending data within the local server. But I couldn't make until I asked Mingna for help, and realizing that creating a https.request to write data to server would be enough for our purpose.

    Takeaways

    • Using rmate to allow editing file in VSCode

    Simply installing rmate from GitHub - aurora/rmate: Remote TextMate 2 implemented as shell script allows editing files way more easier by using VSCode.

    • Using dotenv to enable .env file