On Bitnami LAMP Stack for AWS Cloud, when making code changes, the changes are not immediately visible once the changes have been saved. Even after several refreshes, the server caches the pages. Changes are not visible until the pages are refreshed many times. To disable caching perform the following steps.
PageSpeed is enabled. Disable it by editing the httpd.conf file found at: /opt/bitnami/apache2/conf/httpd.conf
Include conf/pagespeed.conf Include conf/pagespeed_libraries.conf
Comment out the following two lines. Save the file and exit.
PHP has Op Cache enabled. Disable it by editing the php.ini file found at: /opt/bitnami/php/etc/php.ini
Disable this by changing the 1 to 0. Save the file and exit.
Restart the Bitnami LAMP Stack for AWS Cloud instance.
sudo ./ctlscript.sh restart
Your server should no longer cache the pages. Development work should be much easier. When development is complete, you may want to enable PageSpeed and enable PHP Op Cache.
This project uses a Raspberry Pi W Zero to continuously monitor an area for a specific Bluetooth MAC address. When the Bluetooth MAC address is within a certain range, a WeMo connected device is turned on. When the MAC address leaves the area, the WeMo devices is turned off.
There are many use cases for this other than turning a WeMo device on and off. This could easily be modified to initiate any action. For example: send a text or an email when a specific Bluetooth MAC address is near by. Notify you when your kids or wife arrive and leave. Have the device speak a customized greeting using gTTS (Google Text to Speech), etc.
There are many different us-cases.
Raspberry Pi W Zero Starter Kit
You can get the Raspberry Pi components more cheaply on many websites. However, this one has everything you need to start, including a case and power supply.
SanDisk 16GB SD Card
A large SD card isn’t needed for this project. As stated above, this device will only be used to monitor Bluetooth activity.
Igsignia SD Memory Card Reader
This isn’t 100% necessary. If you have a SD card reader, you do not need this. I personally like this because I can install Raspberry Pi operating systems onto SD cards from any computer.
This will be used to let the Raspberry Pi turn on the light.
Setup the SD Card
Download the NOOBs Lite operating system for your Raspberry Pi
There are several ways to install Raspbian on a SD card. I have chosen to use NOOBs in these instructions because it is the easiest for a beginner. NOOBs light is a lightweight bootable interface that allows you to use a Wi-Fi connection to choose the operating system that you want to install. We will be choosing a lightweight OS called Raspbian Stretch Lite. The reason for this is that this Raspberry Pi will serve only one purpose, Bluetooth monitoring. All of the other bells and whistles found in all other Raspberry Pi operating systems are not needed. This is typically refered to as a headless system, one that operates without a monitor. If you don’t want to use NOOBs, you can install Raspbian Stretch Lite directly by downloading it and flashing your SD card with the image. View instructions on How to Install Raspbian Stretch Lite on SD Card.
Unzip the NOOBs Lite zip file. Extract all of the files to a folder on your computer.
Put the SD card into your SD Card Reader and browse to the SD card folder. Copy all of the files extracted from the NOOBs zip file into the root directory of your SD card.
Remove the SD Card from your SD card reader.
Setting up the Raspberry Pi
Insert your SD card into the Raspberry Pi Zero board.
Plug the micro HDMI cable that came with the kit into the Raspberry Pi. Plug the other end into a display of your choice.
Use the micro USB cable that came with your kit to plug in a keyboard.
Plug the power cable that came with the kit into your Raspberry Pi. Plug the other end into a wall outlet.
The Raspberry Pi will boot for the first time.
You will be prompted to select a Wi-Fi network. Select your network and enter your password. This Wi-Fi connection will be used to download the operating system. You may need to flip flop between a USB mouse and keyboard to go through the prompts.
When prompted to select the operating system, choose: Raspbian Stretch Lite
Once connected, your Raspberry Pi will begin downloading Raspbian Stretch Lite. Once complete, your Raspberry Pi will reboot.
When prompted, you may be prompted to enter the default username and password:
It is recommended that you change the default password. It is never a good idea to keep defaults. This can be done using the following command:
Setting up the Raspberry Pi for Bluetooth Proximity
Let’s make sure everything is up-to-date before installing any packages. Issue the following commands:
I personally like using Vi or Vim editor. Enable SSH so that you can control the Raspberry Pi remotely if needed. It is a lot easier to SSH into the Raspberry Pi and mange it than to have it plugged into an external display.
Our Python program was written for and tested against Python 2.7.13. If you want to use a newer version of Python, you may need to modify the code for the Bluetooth Proximity monitor. Check your version of Python:
Edit the script, replacing the temporary Bluetooth MAC address with your own MAC address. On an iPhone, you can find your Bluetooth MAC address by going to Settings > General > About > Bluetooth. Save the file, and run the program:
sudo python bluetooth-monitory.py
Setup Script to Control WeMo Device
sudo pip install peewee
sudo apt-get install git
Navigate to a directory where you want to install the WeMo Control python libraries. Take note, you will need to modify the bluetooth-monitory.py program to use this path. It would make sense to put it in the pi home directory: /home/pi/, Download the repository:
Edit the top of your ./wemo_backend.py (it should be inside the directory that was just created in the above step) file to setup a storage location for database and also make nicknames for your WeMos and their IP addresses. I only have one device and the edited portion of the wemo_backend.py file looks like this. Your IP address and name of the device will obviously be different.
db = SqliteDatabase(‘/home/pi/wemocontrol/database.db’)
If you do not know the path to your WeMo, you can use a network IP scanning tool to find it. An easy app to use on the iPhone to find the IP address of the WeMo is Fing, but there are many tools available.
Run the following commands to setup the database and populate it with some initial values:
Also, test running these commands at the command line to test turning your WeMo device on and off outside of the program. If it doesn’t work via the command line, it definitely will not work inside the Python program.
Run the Bluetooth Proximity Program
sudo python ./home/pi/bluetooth-monitor.py
This will run continuously. Test the output of this script by moving your device around the room. You will see debug output indicating whether you are near or far away from the Raspberry Pi. If you have configured your WeMo correctly, and put the correct commands in the near_cmd and far_cmd variable, the light should turn on and off.
If for some reason your Raspberry Pi were to crash or need to be rebooted, you don’t want to have to run this program every single time. You can add the script to the Raspberry Pi startup so that it will execute every time the Raspberry Pi turns on. You can do so by editing the following file: /etc/rc.local
Right above “exit” enter the command to execute your Bluetooth Monitor script. Save the file. Reboot the Raspberry Pi to test. The following command will execute the Python script in the background when the Raspberry Pi boots.
sudo nohup /home/pi/bluetooth-monitor.py &
I like to restart the device daily. In the event that there is a WiFi connectivity problem or a programming problem, restarting nightly can help reconnect and start the Python script. This can easily be done by creating a cronjob. To create a cronjob to run daily at 8 am, issue the following command:
At the bottom of the file, add:
30 8 * * * sudo /sbin/shutdown -r now
This will run the shutdown reboot command every morning at 8:30 am.
If you frequently export data to csv files, I’m sure you are well aware of the problem when opening those files in Excel. Excel automatically chops off any leading zeros on numbers that start with a zero. This can be a problem for IDs or zip codes that start with a zero. This is a major pain in the ass, especially if you do not want your users to have to jump through hoops to solve the problem. The zeros are actually in the csv, Excel for some reason just hides them.
The below solution will solve the dropping of the leading zero problem. It does not require any extra steps by the user. In your csv file, simply wrap the data that contains the number with leading zeros like so:
“=””0000012345″””,Stiglitz,Hugo,123 Some Street, Some town,Some State
“=””0000054321″””,Soze,Keyser,123 Some Street, Some town,Some State
“=””0000045312″””,Christmas,Lloyd,123 Some Street, Some town,Some State
In the above example, all 4 leading zeros on each ID will be maintained in the excel file when it is opened.