Raspberry Pi GPRS/GPS notes
===

###### 2019-11-01

I'm focusing on a SIM4320(A) chip:

* [Adafruit](https://www.adafruit.com/product/2687)
  - [simcom](https://cdn-shop.adafruit.com/datasheets/SIMCOM_SIM5320_ATC_EN_V2.02.pdf)
  - [sim4320 datasheet](https://www.tinyosshop.com/datasheet/SIM5320_Hardware+Design_V1.07.pdf)
* [DIYmall](https://www.amazon.com/gp/product/B06Y3N1BD6)
* [Arduino SIM5320A](https://www.amazon.com/gp/product/B01HNV3ZXC)

GPRS
---

| Raspberry Pi Pin | FONA Pin | Description |
|---|---|---|
| 3.3v (1) | Vio (4) | Sets logic level, must be externally powered (RPi -> FONA) |
| GND (6) | GND (3) | |
| TXD (8) | RX (6) | RPi transmit -> FONA receive |
| RXD (10) | TX (7) | RPi receive <- FONA transmit |
| GND (6) | Key (11) | Pulse 3-5s to ground to switch state (initially off) |

`Key` is tied to the power button on the FONA.
We want this to be permanently on without the need for
the Pi to turn it on or off, so this should be tied to ground (?).

On the Raspberry Pi (RPi 3B+, Raspbian 2019-07-10 Buster)

```
sudo bash
apt-get update
apt-get install ppp screen minicom

# disable rpi serial interface so we can use it from FONA
# also disable bluetooth and wifi as we don't need it
#
cat >> /boot/config.txt <<EOF
enable_uart=1
dtoverlay=pi3-disable-bt
dtoverlay=pi3-disable-wifi
EOF

# setup ppp configuration
#
cat > /etc/ppp/peers/fona <<EOF
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs"
/dev/serial0
115200
noipdefault
usepeerdns
defaultroute
persist
noauth
nocrtscts
local
EOF

shutdown -r now
```

At this point, after reboot, I tested to make sure the serial connection was at least responding to `AT` commands:

```
sudo bash
minicom -c on -D /dev/serial0
AT
```

* The `AT` command should show up because the FONA should echo the commands
* The FONA should respond with `OK`

---

I was having trouble with a `wwan0` interface coming up.
To have it automatically not show up:

```
sudo bash

cat >> /etc/modprobe.d/raspi-blacklist.conf <<EOF
blacklist qmi_wwan
blacklist cdc_wdm
EOF

# have changes take effect
#
shutdown -r now
```

([src](https://sixfab.com/forums/topic/how-to-remove-interface-wwan0/))

---

To setup a `ppp` connection, issuing:

```
pon fona
```

as root should work.

If there are troubles, look at `dmesg` and `/var/log/syslog` for clues as to what went wrong.

---

I'm having trouble with `ifdown` not recognizing the eth0 interface.

```
ip link set dev eth0 down
```

GPS
---

I'm using an active antennae.

I've soldered the 'bias' bin on the 3G Fona module.

Note that I couldn't find any reference on Adafruit's site about soldering the 'bias' bridge.
I only found this information when looking at other users problems ([src](https://forum.core-electronics.com.au/t/adafruit-fona-gps-not-working/644/8)).
It turns out Adafruit does mention it in one of their PDF guides ([src](https://cdn-learn.adafruit.com/downloads/pdf/adafruit-fona-3g-cellular-gps-breakout.pdf)).

There is a USB connection to the FONA which is how, I believe, the `ttyUSB` interfaces are coming up.
The USB to serial connection can be used for the GPS information whereas the direct serial connection
is used for the GPRS modem.

* I was not getting a fix on the satellites until I soldered the 'bias' bridge on the FONA.
* I had to reseat the small GPS antennae connector
* Connect to serial interface via `/dev/ttyUSB3`
  - Note that `/dev/ttyUSB2` looks to be another viable candidate but maybe what goes on in `/dev/ttyUSB3` is mirrored
    in `/dev/ttyUSB2`
  - `/dev/ttyUSB0` and `/dev/ttyUSB1` show up when the FONA is powered on but I haven't been able to get any response
    when connecting via `minicom` to either of those interfaces
  - to connect from the command line `minicom -c on -D /dev/ttyUSB2` (8N1 115200, hardware flow control off)
* Turn on the GPS functionality by issuing `AT+CGPS=1`
* To poll every 3 seconds with full NMEA message output, issue `AT+CGPSINFOCFG=3,31`
  - Look for the `$GPRMC,...` line as that has the easiest to read lat/lon positions
* To automatically turn on the GPS, use the command `AT+CGPSAUTO=1`.
  - I still don't know how to get polling to automatically work/persist so the `AT+CGPSINFOCFG=3,31` still needs to be issued
    to get GPS data

See [NMEA sentence information](http://aprs.gids.nl/nmea/) and the [AT command set](https://cdn-shop.adafruit.com/datasheets/SIMCOM_SIM5320_ATC_EN_V2.02.pdf).

Connectors
---

I believe the two main connectors are IPEX 1 and SMA.

References
---

* [Initial State tutorial](https://github.com/initialstate/fona-raspberry-pi-3/wiki)
* [Adafruit FONA tethering tutorial](https://learn.adafruit.com/fona-tethering-to-raspberry-pi-or-beaglebone-black/overview)
* [Adafruit FONA 3G tutorial](https://learn.adafruit.com/adafruit-fona-3g-cellular-gps-breakout/overview)
* [Disabling serial port](https://www.cube-controls.com/2015/11/02/disable-serial-port-terminal-output-on-raspbian/)
* [Disable WiFi and Bluetooth](https://blog.sleeplessbeastie.eu/2018/12/31/how-to-disable-onboard-wifi-and-bluetooth-on-raspberry-pi-3/)
* [SO: How do I make serial work on ...](https://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3-pi3b-pizerow)
* [GPS - NMEA sentence information](http://aprs.gids.nl/nmea/)
* [NMEA-0183 messages: Overview](https://www.trimble.com/OEM_ReceiverHelp/V4.44/en/NMEA-0183messages_MessageOverview.html)
* [Adafruit picture of FONA (see soldered bridge with active antenaae)](https://cdn-learn.adafruit.com/assets/assets/000/027/349/original/adafruit_products_Fona_America_top_demo_ORIG.jpg?1440189319)
* [GH: Adafruit FONA Simcom 3G Breakout PCB](https://github.com/adafruit/Adafruit-FONA-SIMCOM-3G-Breakout-PCB)
* [Simcom SIM5320 AT command set](https://cdn-shop.adafruit.com/datasheets/SIMCOM_SIM5320_ATC_EN_V2.02.pdf)
