How to install homebridge on raspberry
First Step
Buy a Raspberry Pi
Actually the link explains everything. I will note that something important and explain how to figure out some tricky problems.
Please following the steps.
Install GCC 7
1 | git clone https://bitbucket.org/sol_prog/raspberry-pi-gcc-binary.git |
Install Node
1 | curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - |
Install Avahi and other Dependencies
1 | sudo apt-get install libavahi-compat-libdnssd-dev |
Install Homebridge
1 | sudo npm install -g homebridge |
Use the following commaned if you got the permission problem.1
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/5.5.0"
1 | sudo npm install -g --unsafe-perm homebridge |
Figure out some problems
You got the error message if you runs the homebridge command. I have a tricky solution. Please following the steps.1
2
3sudo rm -rf /usr/lib/node_modules/
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
Set up the configure and name /home/pi/.homebridge/config.json
1 | { |
Set up boot up
- To save the following words and to name
homebridgeinto/etc/default
1 | # Defaults / Configuration options for homebridge |
- To save the following words and to name
homebridge.serviceinto/etc/systemd/system/
1 | [Unit] |
- Configuration
1 | sudo useradd --system homebridge |
Open your Homekit on your iPhone or iPad
- Import the
homebridgeinto yourHomekit
Plugins
homebridge-server
MUST install the plugin that will helpful to install other plugins and management yourhomebridge
1 | sudo npm install homebridge-server@latest -g |
Add this snippet to your config.json:1
2
3
4
5
6
7{
"platform": "Server",
"port" : 8765,
"name" : "Homebridge Server",
"log" : "/var/log/homebridge-server.log",
"restart" : ""
}
Restart your service and open your browser http://raspberry-ip:87651
sudo systemctl restart homebridge
How to remote control the Homekit
Please set up Home Hub in your iPad
Enjoy your Smart Home
How to install vnc server on raspberry
it’s a simple way to install vnc server. Don’t use default vnc server (Realvnc)
that is not compactable on mac since it need to activate license, however, I
haven’t a monitor to display.
1 | sudo apt-get install tightvncserver |
Now you can use build-in vnc client on mac.
- open
Finderand press⌘+k - In the Server Address enter
vnc://followed by your computer name or IP address.
First, I got a problem that the taskbar disappeared when I remoted to vnc server.
I have had a tricky solution. to remove lxpanel and the taskbar is back.
1 | rm -rf ~/.config/lxpanel/ |
install-info error during update
To compile bluez on the raspberry that got the following message when to install libreadline-dev.
1 | Setting up install-info (4.13a.dfsg.1-5ubuntu1) ... |
It’s a locale problem. You can modify the /etc/environment to correct locale. My solution modify /etc/environment to en_US.UTF-8 and use raspi-config to install en_US.UTF-8. One more thing, don’t forget to run locale-gen to generate locale profile. Reboot your system. All problem solved.
How to figure out `cast from pointer to integer of different size`
When I used cmocka to write the unit test, the compiler alerts a error cast from pointer to integer of different size [-Werror=pointer-to-int-cast]. I have tried to write a unit code for running arm 32-bit and x64 machine however it was not working since I wrote the following code that was only working properly on x64.
1 | assert_false(list_find(list, 11)); |
Let’s figure out the problem since the void pointer.
First try, I rewrite the code on arm 32-bit that convert the void pointer to integer. So that it was working on my raspberry. However it was not working on x64 machine. WTF.
1 | assert_false((int)list_find(list, 11)); |
Since the size of void pointer on x64 is 64-bit and the size of integer is 32-bit. Now the compiler alerts me another error message. How to figure out the problem. Let’s use a type intptr_t. The magic that converts to suitable size on the platform. If you compile the code on x64, it will convert to unsigned long that is 64-bit. Otherwise it converts to int.
1 | assert_false((intptr_t)list_find(list, 11)); |
Django ERROR polls..AppleDouble (unittest.loader._FailedTest)
You got the ERROR: polls..AppleDouble (unittest.loader._FailedTest) when you run the unit test on Django. It means OSX create the .AppleDouble folders in your Django project.
$ find . -name .AppleDouble
./.vscode/.AppleDouble
./.AppleDouble
./__pycache__/.AppleDouble
./polls/templates/.AppleDouble
./polls/templates/polls/.AppleDouble
./polls/.AppleDouble
./polls/__pycache__/.AppleDouble
./mysite/.AppleDouble
./mysite/__pycache__/.AppleDouble
Delete all of .AppleDouble and the problems solved.
$ find . -name .AppleDouble | xargs rm -rf
Updated:
Best solution. You can disable to create .AppleDouble on OSX.
$ defaults write com.apple.desktopservices DSDontWriteNetworkStores true
Writing Matrix-Style
Check out the reference
1 |
|
How to write semaphore on MAC
No shit, just following the code. OSX based on POSIX that it can’t use sem_init to initial the semaphore and it can’t use sem_destroy to destroy the semaphore, too.
1 |
|
What is different with malloc and sbrk
I was refactoring the project because sometimes the project crashed. Analyzing the code I found it is the problem of memory managemnt. Sometime it use the wrong address when it free the memory. In the project, it didn’t use malloc of GNU C library to allocate the memory and it implemented the feature.
The following code is a basiclly malloc implementation from stackoverflow. It use sbrk to implement malloc. I was confusing why it use a low-level function to implement malloc allocating the memory. What is different with malloc and sbrk?
1 | void* malloc(size_t size) { |
What is different with malloc and sbrk?
sbrk is a low-level function in GNU C library. From wikipedia said that brk and sbrk are basic memory management system calls used in Unix and Unix-like operating systems to control the amount of memory allocated to the data segment of the process. sbrk supports to allocate the memory but it isn’t flexible to use memory that means it can’t use released memory. You can follow the code and I used static memory to refactor malloc. The code allocated a huge array and it retured the pointer address to new block if it wasn’t released memory.
1 |
|
Finally I can show you the implement code that what you want.
1 | typedef struct free_block { |