Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Last active November 24, 2023 17:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tomysmile/1dc9b9aebd41da6751e0 to your computer and use it in GitHub Desktop.
Save tomysmile/1dc9b9aebd41da6751e0 to your computer and use it in GitHub Desktop.
Raspberry Pi Installation using Mac OSX

Raspberry Pi Installation using Mac OSX

Installing Raspbian

First we need to download raspbian, you can grab the latest version at https://www.raspberrypi.org/downloads/

Direct url: http://downloads.raspberrypi.org/raspbian_latest

Now we need unzip the file: 2016-02-06-raspbian-jessie.zip: unzip 2016-02-06-raspbian-jessie.zip

You will get a file named 2016-02-06-raspbian-jessie.img, this file must be written to your micro-sd card.

Re-Formatting your SD Card

Using Gui

Download and install the SD Association's Formatting tools from https://www.sdcard.org/downloads/formatter_4/eula_mac/

Select "Overwrite format", Make sure you have selected your SD Card, and not something else Click "Format"

Using Terminal

First, look at the partition table by running this command:

diskutil list

You should see something like this:

/dev/disk1
#:                       TYPE NAME                    SIZE       IDENTIFIER
0:      GUID_partition_scheme                        *16.0 GB    disk1
1:                        EFI                         209.7 MB   disk1s1
2:                  Apple_HFS Example                 15.7 GB    disk1s2
The partition we want to change is /dev/disk1.

We want to change the device to an MBR-formatted FAT32 partition. To do that, run this command:

sudo diskutil eraseDisk FAT32 [NAME] MBRFormat /dev/disk1

Where [NAME] must be written in CAPITAL letters; otherwise, this will not work.

As mentioned in the comments, you cannot put square brackets into the volume's name lest things mess up. To avoid having everything fail, simply ensure that there are no square brackets in the FAT32 volume's new name.

Flash the Image onto Your SDCard

Format the SD Card

Formatting an SD card is quite straight forward with Mac OS X. Start by pressing CMD SPACE to reveal the Spotlight search bar at the top right hand side of the screen. In this search bar, type disk utility and press return to launch the Disk Utility application.

Select the SD card, in the left hand pane, and then select Erase ensuring that the format is MS-DOS (FAT).

Identify the SD Card

Flashing an SD card is quite straight forward with Mac OS X. Start by pressing CMD SPACE to reveal the Spotlight search bar at the top right hand side of the screen. In this search bar, type terminal and press return to launch the Terminal application.

Insert the SD card into your Mac’s SD card drive.

To find the connected SD card, in the terminal window type:

diskutil list

Make a note of the identity of yours. In my example it is /dev/disk2 but yours may be different.

If the SD card was automatically mounted, as mine way, you will need to unmount it with the following command in Terminal. Remember to correctly identify your SD card if it is a different number to my example.

diskutil unmountdisk /dev/disk2

Navigate to the location that you downloaded and extracted the .img file from the .zip download. In my case it is the Downloads directory.

cd Downloads/

TIP: The dd command is very powerful and you risk serious corruption to your Mac if you use it incorrectly. Triple check your command before executing it, or use a different method (described below) to flash your SD Card if in doubt.

Flash the SD Card

You'll be shown a message that your SD card has been unmounted. Its disk image will disappear from the desktop.

Here's where you want to pay close attention. We want to type in a command such as:

sudo dd if=~/Downloads/2014-01-07-wheezy-raspbian.img of=/dev/disk2 bs=2m

It will then take a few minutes to flash the SD card during which time no progress information will be shown. Be patient. On completion, you will get a confirmation with some information displayed in terminal.

You are now free to unmount the SD card for use in your Raspberry Pi.

Configure RPi WiFi

First, modify your network interface file:

sudo nano /etc/network/interfaces

For having dynamic Ip Address, The configuration should be similar like below:

# /etc/network/interfaces

auto lo

iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

then continue modifying your wpa_supplicant file:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

the content should be something like below:

country=ID
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
 ssid="YOUR_WIFI_SSID_NAME"
 psk="YOUR_WIFI_PASSWORD"
}

You might want to modify the configuration above, such as your SSID and Wifi password. Remember no space between "=". That's it, just reboot your Pi and do the 'ping' to test.

Generating SSH Key on Raspberry Pi

If somehow you can't connect to your RPi, try to regenerate the keys by doing these:

ssh-keygen -t 'dsa'
ssh-keygen -t 'rsa'

now try again to connect to SSH:

ssh pi@xxx.xxxx.xxx.xxx

How to Update & Upgrade your RPi

here's how, On the command line, type in:

sudo apt-get update
sudo apt-get upgrade

Both of these commands will give you a lot of gobbledygook. You will wait awhile. Be patient. These update package lists from the various repositories and updates them to get information on the newest versions of packages and their dependencies.

when done:

sudo reboot

Send SMS messages using Raspberry P Using gammu and Wavecom M1306B (USB)

  1. Install Gammu (python-gammu and gammu-smsd can be skipped - depending on requirements)
sudo apt-get install gammu python-gammu gammu-smsd
  1. Find port USB device connected to dmesg | grep tty

[ 7.578478] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB0 [ 7.697942] usb 1-1.2: GSM modem (1-port) converter now attached to ttyUSB1

  1. Config gammu

Run this command

gammu-config

Gammu configuration sample

If you are using gammu-config command above, it will create this file automatically in your home folder, ex: /home/pi/.gammurc

[gammu]

port = /dev/ttyUSB0
model =
connection = at115200
synchronizetime = yes
logfile =
logformat = nothing
use_locking =
gammuloc =
  1. Check connected gammu --identify

Device : /dev/ttyUSB0 Manufacturer : Wavecom Model : MULTIBAND 900E 1800 (MULTIBAND 900E 1800) Firmware : xxxxx IMEI : 3XX19301XXXXXX3 SIM IMSI : 2XXXX923271XXX1

  1. Test with a text message
echo "some message" | gammu --sendsms TEXT 07921XXXXXX
  1. Create required directories

    mkdir -p /var/log/gammu /var/spool/gammu/{inbox,outbox,sent,error}
    

    Note:

    • The directory names are case-sensitive
  2. Setup Gammu spool directories owner and permission

    In this example your webserver's user and group is www-data

    chown www-data:www-data -R /var/spool/gammu/*
    

    You can also set files and folders permission to world-writable

    chmod 777 -R /var/spool/gammu/*
    
  3. Get example of gammu-smsdrc from playSMS package and copy to /etc/

    wget -c https://raw.githubusercontent.com/antonraharja/playSMS/master/contrib/gammu/linux/gammu-smsdrc
    cp gammu-smsdrc /etc/
    

    Note:

    • Before continue to the next step you have to take a look at /etc/gammu-smsdrc and edit the file accordingly
    • Try to identify your modem by running gammu --config /etc/gammu-smsdrc identify
    • You may need to adjust the port and connection options
    • Mostly you do not need to change other options
    • Do not change the file or directory paths
  4. Run gammu-smsd

    /etc/init.d/gammu-smsd start
    
  5. Verify if gammu-smsd is running

    ps ax | grep -v grep | grep gammu-smsd
    

    Monitor Gammu smsd log file:

    tail -f /var/log/gammu/smsd.log
    
  6. Runs as Daemon (SMSD)

    sudo gammu-smsd -c /etc/gammu-smsdrc
    
  7. Test send email using Daemon

    gammu-smsd-inject -c TEXT 123456 -text "Hi, this is from Pi."
    

Installing LAMP on RaspberryPi

In this tutorial the preparation is done for Ubuntu with LAMP stack.

  1. Upgrade

    sudo apt-get update
    sudo apt-get upgrade
    
  2. Install LAMP stack and some PHP extensions

    sudo apt-get install apache2 libapache2-mod-php5 mysql-server php5 php5-cli php5-mysql php5-mcrypt php5-gd php5-imap php5-curl
    
  3. Enable mcrypt extension manually:

    sudo php5enmod mcrypt
    
  4. Restart apache2

    sudo service apache2 restart
    
  5. Browser http://localhost and see if the web server is serving

  6. Download playSMS package from https://sourceforge.net/projects/playsms/files/playsms/ and save it or upload it to the server. This is the latest playsms stable version http://nchc.dl.sourceforge.net/project/playsms/playsms/Version%201.3.1/playsms-1.3.1.tar.gz

Installing PlaySMS on Raspberry Pi

Ubuntu Setup

Before installing playSMS the server must be prepared by installing required applications. In this chapter the preparation is written for Ubuntu with Apache2, MySQL and PHP.

Upgrade Ubuntu

sudo apt-get update
sudo apt-get upgrade

Install LAMP stack and some PHP extensions

sudo apt-get install apache2 libapache2-mod-php5 mysql-server php5 php5-cli php5-mysql php5-mcrypt php5-gd php5-imap php5-curl

Enable mcrypt extension manually

sudo php5enmod mcrypt

Restart apache2 sudo service apache2 restart

Browser http://localhost and see if the web server is serving

Back to Linux console and setup MySQL server.

Setup MySQL root password

mysqladmin -uroot -p password <your_new_secure_password>

MySQL first time password is empty, just press Enter when prompted.

Create playSMS database

mysqladmin -uroot -p create playsms

Create playSMS user

$ mysql -u root -p
mysql> CREATE USER 'playsms'@'localhost' IDENTIFIED BY '[your_password]';
mysql> GRANT ALL PRIVILEGES ON playsms.* TO 'playsms'@'localhost' WITH GRANT OPTION;
mysql> flush privileges;
mysql> quit;

Download playSMS package and save it in the server

We are ready to install playSMS. Next, you need to choose installation method. Choose one which is easier. For starter I recommend to choose installation using provided install script.

Installation Using Install Script

Install playSMS using install script install-playsms.sh. The script is included in playSMS release package. Current official release is playSMS version 1.3.1.

Please note that before following below steps you need to cover all steps required in Ubuntu Setup. Extract playSMS package and go there (For example in /usr/local/src)

sudo tar -zxf playsms-1.3.1.tar.gz -C /usr/local/src
ls -l /usr/local/src/
cd /usr/local/src/playsms-1.3.1/

Copy install.conf.dist to install.conf and edit install.conf Read install.conf and make changes to suit your system configuration

sudo cp install.conf.dist install.conf
sudo nano install.conf

Run installer script

sudo ./install-playsms.sh

Configure rc.local to get playsmsd started on boot Look for rc.local on /etc, /etc/init.d or /etc/rc.d/init.d

When you found it edit that rc.local and put: /usr/local/bin/playsmsd start

on the bottom of the file (before exit if theres an exit command). This way playsmsd will start automatically on boot.

Note:

After successful installation, please run command ps ax and see if playsmsd is running ps ax | grep playsms

4069 pts/12 S 0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf schedule 4071 pts/12 S 0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf dlrssmsd 4073 pts/12 S 0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf recvsmsd 4075 pts/12 S 0:00 /usr/bin/php -q /usr/local/bin/playsmsd /etc/playsmsd.conf sendsmsd

Run several checks

sudo playsmsd status
sudo playsmsd check

Stop here and review your installation steps when playsmsd is not running Consider to ask question in playSMS forum when you encountered a problem If all seems to be correctly installed you may try to login from web browser

URL                    : http://[your web server IP]/playsms/
Default admin username : admin
Default admin password : admin

Configuring Gammu in OSX with MySQL

Requirements:

Step by step:

  • Check the sql files in here
$ cd /usr/share/doc/gammu/examples/sql

or from https://github.com/gammu/gammu/blob/master/docs/sql/mysql.sql


- runs below commands:

$ wget https://raw.githubusercontent.com/gammu/gammu/master/docs/sql/mysql.sql $ mysql -u root -p mysql> create database gammu; ok mysql>quit


## Create User for Gammu

```sh
$ mysql -u root -p
mysql> CREATE USER 'gammu'@'localhost' IDENTIFIED BY 'gammu';
mysql> CREATE USER 'gammu'@'%' IDENTIFIED BY 'gammu';
mysql> GRANT ALL PRIVILEGES ON gammu.* TO 'gammu'@'localhost' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON gammu.* TO 'gammu'@'%' WITH GRANT OPTION;
mysql> flush privileges;
mysql> quit;

Import from MySQL

$ mysql -u root -p gammu < mysql.sql
mysql> show tables;
  • Configure SMSDRC
$ sudo touch /etc/gammu-smsdrc
$ sudo nano /etc/gammu-smsdrc

/etc/gammu-smsdrc

port = /dev/(your_device)
connection = (your_connection)
startinfo = yes
# Debugging
logformat = textall
# SMSD configuration, see gammu-smsdrc(5)
[smsd]
service = mysql
driver = native_mysql
deliveryreport = sms
logfile = /var/log/gammu/smsd.log
debuglevel = 255
pin = 1234
user = root #your mysql user
password = 123456789 #your mysql password
pc = localhost #Server Mysql
database = gammu #DB name
phoneid = modem_1
-

Running Gammu Daemon

Run gammu-smsd with this command on your terminal : (it will runs the daemon with config from /etc/gammu-smsdrc)

$ sudo gammu-smsd

or for specific configuration file

$ gammu-smsd -c ~/.gammu-smsdrc

To Test your installation, you can try these two ways :

  • Insert to SQL
INSERT INTO outbox (DestinationNumber, TextDecoded, SenderID, CreatorID, Coding) VALUES (‘123456’, ‘Hi, this is sierra.’, ‘sierra’, ‘sierra’, ‘Default_No_Compression’);
  • Inject thru Command
gammu-smsd-inject -c /etc/.smsdrc-sierra TEXT 123456 -text “Hi, this is sierra.”
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment