Posts

googletest on Ubuntu

Image
Running gtests on your C++ programs using g++ on Ubuntu: Installation Install CMake: sudo apt install cmake Switch to home directory and: git clone --depth 1 https://github.com/google/googletest.git Build it: cd ~/googletest mkdir build cd build cmake -Dgtest_build_samples=ON -Dgtest_build_tests=ON ~/googletest make make test ./googlemock/gtest/sample1_unittest Install the googletest and googlemock .a and .h files: sudo cp -r -v ~/googletest/googletest/include/gtest /usr/local/include sudo cp -r -v ~/googletest/googlemock/include/gmock /usr/local/include sudo cp -v ~/googletest/build/googlemock/lib*.a /usr/local/lib sudo cp -v ~/googletest/build/googlemock/gtest/lib*.a /usr/local/lib TEST() and code in same file - Test Fail To compile and run: g++ 01sqrt_fail.cpp -lgtest -lpthread -o 01sqrt_fail ./01sqrt_fail Output: TEST() and code in same file - Test Pass To compile and run: g++ 01sqrt_pass.cpp -lgtest -lpthread...

MNO LAN: Use same MNOs SIM card in your IoT devices like GL-MiFi

Image
One of the big issues with IoT is somehow enabling two end nodes to communicate with each other in the presence of  Network Address Translation (NAT) Now days most ISPs (and Mobile Network Operators or MNOs) use NAT by default and assign you local IP addresses in 10.*.*.* subnet. You usually have to pay an extra fee to get static global IP addresses assigned to you - this could be a security concern. If your end nodes run embedded linux, the following solutions can be used: Use DDNS and UPnP together DDNS is not usually free, but the manufacturer of your embedded linux device (routers from goodlife of Vstarcam's IP camera) might provide you this service for free as it uses almost nil resources on the server side. Most ISPs have UPnP support disabled on their gateway. In a home environment, if you have your own static global IP for your home router, you can use UPnP and DDNS to your advantage. An end node will use UPnP to request your WiFi Router to open ad forward certain ...

TurboPower

Image
We all want our smartphone to charge quickly. And different phone manufacturers have either created their own propriety method of charging (Oppo VOOC or MediaTek PumpExpress+ or Motorola's TurboPower or OnePlus's Dash) or have opted to comply with a industry wide standard like Qualcomm's Quick Charge series of standards). These technology work my allowing a phone to tell the charger to step up the voltage beyond 5 volts so that the power available to the phone for charging the battery is more than what a good 5 volt / 2 ampere wall/car charger can supply. I have a Moto G4 plus and I wanted to make sure that I had access to fast charging at home/office, in car or while travelling. So I went ahead and got the following accessories My Moto G4 plus along with the various charging accessories Voltmeter USB Voltmeter Stick ...

Food Silicone food savers + Glass bottles

Image
Plastics! Cancer! Correlation! And so we move away from plastic bottles to glass bottles. But glass bottles pretty but fragile. So what do we do? We get food huggers!!! Food huggers seemed onle somewhat useful to me all this while until now The silicone rubber food huggers will protect the bottom of the bottles - I was worried that I might end up banging them on the floor when I have a sip in the middle of the night. Color Glass bottles  + Silicone food hugger  = Amazon.in links: Food huggers/savers Glass bottles Note: The food huggers come as a set of 4. Only the two larger ones have diameters large enough for the glass bottles linked to above. The smaller two won't fit. So if you get 6 bottles, you will need to order 3 sets of ...

Adding new elements to OpenWrt's LuCI on GL-MiFi

If you are an IoT enthusiast who uses devices that run OpenWrt (routers from Goodlife , or MT7688 ), you would have considered creating a plugin for LuCI so that you can expose the functionality of any sensors/actuators that you may have connected to your OpenWrt box via OpenWrt's builtin web console. This article on openwrt.org's wiki will tell you exactly how to do that. As maybe obvious from the page, if you want to create dynamically generated web content, you will need to write lua scripts. When trying out the steps from the wiki article for my GL-MiFi , I had to modify the file locations for placing various script like so: new_tab.lua had to be placed in: /usr/lib/lua/luci/controller/myapp   cbi_tab.lua had to be placed in: /usr/lib/lua/luci/model/cbi/myapp-mymodule   cbi_file can be put in the same place as mentioned: /etc/config view_tab.htm had to be placed in: /usr/lib/lua/luci/view/myapp-mymodule Once I had the placed the files in the right loc...

Build system comparison for C shared library: Manual vs. Makefile vs. Bazel

Image
Here is a simple code for shared library (.so) and an executable that uses it: Library Source files (libhello.c and libhello.h): Source for the executable that uses the above library (main.c): There are many ways to build and execute these sources. Lets look at three of them. The first one is a collection of manual commands that you need to execute in a particular order. The other two uses some form of build system. Before you proceed, make sure to have the C compiler installed on your Ubuntu PC. To do this, execute the following at the command prompt: sudo apt-get install build-essential git Manual build: (Reference: http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html ) Place the three source files in the same directory. Open the command prompt, switch to the same directory and execute the following commands to compile, execute and clean: Compilation Compiling the library sources into object files with Position Independent Code: gcc -c -Wal...

My favourite alias in .bashrc on Ubuntu

Image
Colorizing and handling system/kernel logs alias logread='cat /var/log/syslog | ccze -A' alias logclear='sudo truncate -s 0 /var/log/syslog' alias logsave='cat /var/log/syslog | ccze -h > ~/log.html' alias dmesgread='dmesg | ccze -A' alias dmesgclear='sudo dmesg -c' alias dmesgsave='dmesg | ccze -h > ~/log.html' You will have to install ccze (sudo apt-get install ccze)