Showing posts with label AIS. Show all posts
Showing posts with label AIS. Show all posts

Monday, 11 July 2016

dAISy off-grid receiver

Off-grid AIS Station is now live on marinetraffic:
Receiver altitude is approx. 230m ASL, so should be better

Station coverage:
https://www.marinetraffic.com/en/ais/details/stations/910/

Remote unit battery level monitor real-time
https://thingspeak.com/channels/113422
https://io.adafruit.com/steve098/aismon

Compare the receiption to the Moxon square RTL-SDR receiver in my loft at sea level,
https://www.marinetraffic.com/en/ais/details/stations/1618/

The remote receiver picks up vessels in Oban Bay more reliably (not surprising as it can see over the top of several hills compared to my home station), and sees 'around the corner' into the Sound of Mull better, being able to track the Loch Fyne CalMac ferry on most of its route from Lochaline to Fishnish on the Isle of Mull.

It sacrifices coverage up Loch Creran.


Todo:
* convert daisy to 3.3v operation. I have received advice from Adrian Studer on how to fix excess power drain when operating the dAISy at 3.3v by isolating the 3.3v LDO reg.
* convert the AIS parser script that powers the Twitter feeds @ObanAIS and @ObanSARwatch to accept AIS sentences from the remote receiver.



Thursday, 2 June 2016

Raspberry Pi RTL-SDR AIS marinetraffic image

Here is a Raspberry Pi SD card image that will decode AIS messages on VHF radio using an RTL-SDR dongle.

It will upload the data to marinetraffic.com (you will need to sign up to marinetraffic.com for this) and also broadcast the AIS sentences on your local area network.

This way, you can use the Raspberry Pi and RTL-SDR as an AIS receiver for OpenCPN

I have shrunk the image to fit on Dropbox.

Image file (.zip) for Raspberry Pi: *8GB SD card*

https://www.dropbox.com/s/pflj3xtczzfb2p2/marinetraffic_rtl_sdr01.zip?dl=0

Edit July 2017 - new link:

https://www.dropbox.com/s/p4wqacko4ru3jpl/marinetraffic_rtl_sdr01.zip?dl=0

~1.6GB download

Instructions for copying an image to SD card are given here:
https://www.raspberrypi.org/documentation/installation/installing-images/windows.md

Setup Instructions:

https://www.dropbox.com/s/nez9zzmkkcxcky4/Raspberry%20Pi%20RTL-SDR%20AIS%20receiver%2001.pdf?dl=0

https://www.dropbox.com/s/1q21f23xkysovd5/Raspberry%20Pi%20RTL-SDR%20AIS%20receiver%2001.pdf?dl=0


[update March 2017 - Fitipower FC0012/13 chips have different gain ranges than the suggested values in the notes. My notes are for RT820x based RTL receivers. To see your receiver's allowable gain values, 1) log into Pi via SSH2) stop the AIS code from auto running:   sudo nano ~/ais.sh 
   change line to GO=0
3) reboot the Pi (sudo reboot)
4) log in again, and run the commands:
    cd /usr/local/bin
    rtl_test
   (exit with CTRL-c)
This will list the allowable gain values for your device. Edit ~/ais.sh to use your new gain value.

I am by no means an expert. This image works for me. YMMV. I welcome feedback and improvements.

You might consider using KPLEX http://www.stripydog.com/kplex/examples/marinetraffic.html to distribute AIS to marinetraffic as well as local network addresses, instead of the 'pipe tee' method used on the image.

Thursday, 19 May 2016

source code on GIT

source code for the AIS receiver/repeater (Teensy 3.1):
https://github.com/beinnlora/AIS-repeater

credit to Stuart Robinson for the base LoRa code
https://www.dropbox.com/sh/na2d9yt09nr91f7/AADqSNprExezpBEcqIxewDpBa?dl=0


source code for the Raspberry Pi LoRa gateway:
https://github.com/beinnlora/lora-gateway

credit to Dave Ackerman for the base LoRa code
https://github.com/PiInTheSky/lora-gateway

Thursday, 12 May 2016

remote AIS receiver/repeater - part 9 - more power measurements

[prev]     [first]     [next]  

I have moved the dAISy to being powered via the 5v pad direct from Vbat (3.7-4.2V) since the power consumption is (perversely) much lower at 5V than 3V

I have changed the threshold for the microcontroller to send everything to sleep up to 3.6V.

Total system current now idles at 38mA @ 4V which is a great improvement.

The Teensy is drawing around 19mA at 4V. This will be the next target for power optimisation.

There may be a way of putting the teensy into micro sleeps - if we can profile the AIS traffic in an area and perhaps predict from the protocol timing if we can sleep at a given moment by sacrificing position update frequency for high-data-rate vessels for example, that would be an OK tradeoff

There is an odd anomaly with the dAISy when powering via 3.3V pad vs 5V pad - configuring the dAISy to output at 9600 baud is ignored when powering at 3.3V - serial data rate is 38400. However, move to powering via the 5V pad and the baud rate setting is reduced to 9600 as per the setting. The manufacturer is looking into it.


remote AIS receiver/repeater - part 8 - more dAISy current measurements

[prev]     [first]     [next]  

powering the dAISy from the 3.3v pad and current consumption for the dAISy runs at about 71mA (234mW)

powering the dAISy from the 5v pad at 4.1V takes about 17mA (70mW)

Some difference!

However, if I power the dAISY from the 3.3v, the battery can get down to about 3.2V before the dAISy stops receiving, but from the 5v pad, it gets flaky at 3.6V

I guess strictly I shouldn't be dragging the 18650 cells down this low, but it is all extra capacity useable down from 3.6 to 3.3Vbat, but what a power difference.

Threshold for system sleep is 3.3Vbat at present. I think I will up this to 3.6V, power the dAISy on the 5V pad and hope for the best.

I could do some calculations comparing the lost capacity vs overall consumption...

Friday, 6 May 2016

remote AIS receiver/repeater - part 7 - current measurements

 Overall power consumption measurements

[prev]     [first]     [next]
Overall system current @ battery voltage (3.7-4.2V). Active=transmitting LoRa, Standby=listening.

dAISy current measured at 3.3V (via output of onboard 3.3v Regulator on Teensy) Active = receiving/parsing. AIS sentence. Standby = listening

Teensy current  @ battery voltage with no peripherals powered up, taken from internet (not yet measured)

HopeRF not measured




active standby sleep
Overall 110mA 95mA 0.2mA
dAISy 77mA 74mA  0
Teensy ~20mA ~20mA 0.2mA
Hoperf

~0mA


Our challenge is to tame the dAISy which is someway off the published spec (<20mA @ 5V i.e.  100mW; we are seeing 74mA @ 3.3v i.e. 250mW)

Tuesday, 3 May 2016

remote AIS receiver/repeater - part 6 - power performance

Power budget

  [prev]     [first]     [next]
The dAISy has arrived. A quick comparison with the RTL-SDR and the RF sensitivity is about the same. (geography is my main limiting factor)

I am powering the dAISy via 3.3v header on the PCB rather than USB, and receiving AIS sentences via the hardware TX pin. The dAISy utility seems to ignore me setting the onboard serial data rate to 9600baud, and continues to spit out at 38400, but the Teensy can handle this fine.

The remote unit periodically spits out its voltage over the LoRa link, whereby the Raspberry Pi logs this to the cloud to see battery performance over time

I am logging the voltage of the battery to thingspeak, which are plotted below. Values below are raw ADC values (12 bit input. 4.2V battery voltage scaled to 1.2V to match the Teensy 3.1 internal Vref ), and averaged over the last 10 readings

.
Readings are currently send from the remote device every 20 seconds, but at present the Raspberry Pi receiver crashes about once a day when a corrupt packet is received.

I am uploading to marinetraffic.com which gives some (delayed) statistics on AIS message rate to give me some idea of the number of AIS sentences I am likely to  transmit

Current draw from the battery is 90mA @ 4.1v (0.37Watts)  idle, rising to about 120mA (0.5W) on LoRa transmit, but not measured very precisely. Most of this is the dAISy

When the battery voltage drops below about 3.6V, I have the Teensy turn off the dAISy receiver and put the HopeRF  into sleep, before itself sleeping for 20 seconds.

Every 20 seconds it wakes to measure the battery voltage, then sleeps again if needed.

Sleeping current is around 200uA, which can be improved with some effort
 , but should not be significant


Friday, 29 April 2016

remote AIS receiver/repeater - part 5 - base station

 [prev]     [first]     [next]

TL;DR

Raspberry Pi LoRa gateway


* Raspberry Pi 2/3 with HopeRf RFM98 shield from store.uptronics.com
* antenna can be yagi
* software on Pi adapted from Dave Ackerman's LoRa gateway software for High-altitude baloons
http://www.daveakerman.com/?p=1719
* Pi receives messages from LoRa and reconstructs full sentences (!AIVDM header is stripped from the on-air backhaul to save size, so is reconstructed on the Pi before pushing to the LAN over UDP
* pi also receives battery level from the remote receiver and publishes to IoT cloud e.g adafruit.io




remote AIS receiver/repeater - part 4 - LoRa data link


  [prev]     [first]     [next]

TL;DR

LoRa data link

* Transmitter HopeRF RFM98 433MHz HopeRF RFM98W-433S2
* code adapated from various sources listed on  kh-gps.de/lora.htm

Antenna is just 1/4 wire at the moment, but could be directional yagi/moxon, given that it need only point in one direction.


remote AIS receiver/repater - part 3 - power management


[prev]     [first]     [next]
TL;DR
* 10W 12V solar panel
* 2x18650 LiPo
LT3652  based Solar LiPo charge contoller
* Teensy 3.1 microcontroller for power management.


I want about 5 days of solar redundancy to allow for Highlands weather.

Instead of having a transparent serial link whereby all AIS sentences are just packetised and transmitted over the LoRa, we waste a lot of energy on partially-full LoRa packets, redundant AIS sentences and possible brownout at night. We want to be able to control the LoRa radio state too by using sleep mode to minimise current draw (we don't need it to receive any messages over LoRa just yet)

If we control the LoRa transmissions and AIS reception with a microcontroller, we can optimise power usage by pre-filtering sentences and packaging up several AIS sentences in on LoRa data frame (max 258bytes - could get perhaps 3 AIS sentences in one LoRa packet ). We can also monitor the power and switch off the AIS receiver when the battery is low or rate limit packets as the input current allows. There is a tradeoff between the extra draw of a microcontroller and that saved by optimising packets. We don't have to receive any information back through the LoRa link (unless we want to at a later date), so we can put it to sleep outside transmissions.

I have a few Teensy 3.1 controllers knocking around which are more than overkill for the job,but they seem suitable because
* 3.3v power possible for low current
* underclock easy for low current
* Snooze library good for low power mode
* good HW serial support for buffering AIS sentences
* good number crunching abilities should we wish to add AIS decoding/prefiltering

Some fag packet calculations. I have made up some assumptions on AIS packet data rates. The LoRa parameters are critical for power consumption - different coding rates, spreading factors etc all vary the packet transmission duration significantly, so I have just made a guess here based on some mid-range figures from the Semtech LoRa calculator

Device On state Sleep State
LoRa 130 2 mA
Teensy 20 1 mA
Ais 20 mA
Teensy duty cycle 0.75
time per sentence 0.15 s
sentences per min 120
sentences per hour 7200
tx time per hour 1080 s
calculated lora duty cycle 0.3
LoRa mean current over 1 hour 40.4 mA
Average total current draw over 1 hour 75.4 mA
energy used in 1 day 1809.6 mAh
battery capacity 5500 mAh
battery duration (no solar input) 136.1 hours
5.67days
solar panel Current @Pmax 550 mA
sunshine per day 4 hours
solar input per day
2200 mAh
time to full charge @ max flux 10 hours



I happened to have a 12V 10W solar panel going spare, so used this. I have a stash of 18650 cells too. Two in parallel give me 5500mAh.

The solar charge controller - I would have liked this from Adafruit  https://www.adafruit.com/products/390 but it is not available locally and only handles a 6V panel

but it didn't handle the 12V (20V open circuit) from my existing solar panel, so I chose one based on the LT3652 charge controller chip

https://www.sparkfun.com/products/12885

out of the box it required a bit of tinkering to get going. The board is set for a 4 hour timer using a 1uf cap on pin 6 of the LT3652 . I bypassed this to allow full current to the board (connected in parallel with the battery) when the sun is shining. Battery charge is then current - rather than time - limited.
There are options on the board for current sense resistors, which I could use to rate-limit the AIS backhaul based on available current should I so desire at a later date



remote AIS receiver/repeater - part 2 - AIS receiver

[prev]     [first]     [next

TL;DR
* dAISy AIS receiver running at 3.3v  3.7 - 4.2V and direct serial output
http://www.wegmatt.com/
* homemade 5 element colinear at 162MHz or Moxon rectangle (reception azimuth is limited)
http://arundale.com/docs/ais/aerial.html
http://w4.vp9kf.com/moxon_calculate.php




Originally I used a Raspberry Pi and RTL-SDR dongle to receive AIS messages at home, but this requires too much power for solar operation if my receiver/repeater is going to live on a remote hilltop

I have settled on a small standalone receiver called dAISy http://www.wegmatt.com/. Purchased from Tindie, not yet arrived from the USA.

The creator has been very helpful answering some technical queries about boot times, power management and reception advice.

The unit can be powered from 3.3v and output AIS messages over TTL serial. Power <20 mA@5V (untested at 3.3v)

Receiver is apparently easily desensitied by nearby transmitters, so need careful placement away from the LoRa transmitter




Remote AIS receiver/repeater

I live close to the sea, and my kids love seeing the comings and goings of boats into town on their way to school. I have an AIS receiver in the loft that feeds data to our local network and to the chart software on my laptop. I'm then primed each morning to answer the kid's questions of "What's that boat Daddy? Where is it going? Where is it from?".

When the search-and-rescue helicopters fly overhead to refuel at the local airfield, I get a ping from Twitter to tell me to point it out

I have AIS envy though. We are *just* in range of the larger ships entering town, but smaller fishing vessels are just out of range, hidden behind some big lumps of granite. The Scottish geography is not my friend here; across the bay just over 5 miles away is a receiver on top of a big hill - that receiver sees EVERYTHING, and I am jealous.

Here enters the gadget tinkerer, throwing his latest acquired technology toolkit towards the problem. I'm tinkering with a wireless race tracker project at the moment, which involves LoRa data links, GPS position reporting and low power/battery power design, so it's just one small step up to building a solar powered AIS receiver to plonk on a local hilltop and use the LoRa radio link to backhaul the AIS messages to my house.

There's a few parts to this project:
* AIS reception
* LoRa backhaul
* solar power management
* LoRa basestation and AIS WAN uplink

I'll cover each section in a separate post


Tuesday, 9 February 2016

Rasperry Pi RTL-SRD AIS tracker for OpenCPN and MarineTraffic.com

Raspberry Pi 2 Model B
RT820T based RTL SDR USB dongle
1/4 wave groundplane antenna / moxon loop



I have a raspberry Pi 2 running with RTL-SDR USB stick successfully feeding AIS to marinetraffic.com  and to my local network. The rough steps (and links to guides are below)

Start with fresh install of raspbian Jessie lite 2016-5-10

Install RTL SDR on Raspberry Pi and add to blacklist of USB devices: http://goo.gl/tXnW13.
sudo apt-get update

Now install the required utils to compile the RTL-2832U USB dongle driver

sudo apt-get install git 
sudo apt-get install cmake
sudo apt-get install libusb-1.0-0.dev
sudo apt-get install build-essential

Now install the RTL-2832U USB dongle driver src and compile

git clone git://git.osmocom.org/rtl-sdr.git
cd rtl-sdr/
mkdir build
cd build
cmake ../
make
sudo make install
sudo ldconfig

Edit the following file /etc/modprobe.d/raspi-blacklist.conf

use your favourite editor like nano or vi 

sudo nano /etc/modprobe.d/raspi-blacklist.conf

add the following lines in the file.

blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830


Save and exist.
 (ctrl-X --> y -->enter)

REBOOT then plug in your RTL-SDR stick

Confirm the RTL is working using rtl_test first before proceeding:

sudo rtl_tcp -t

Install gnuradio(dev) http://goo.gl/TVogHw  (takes a long time!) :
sudo apt-get install gnuradio gnuradio-dev
install osmosdr:
sudo apt-get install gr-osmosdr

install Boost
sudo apt-get install libboost1.50-all

install Cppunit:
sudo apt-get install libcppunit-dev

install liblog4cpp5:
sudo apt-get install liblog4cpp5-dev

install socat:
sudo apt-get install socat
install swig:
sudo apt-get install swig

install gr-ais https://goo.gl/QXXzhO.  :

 git clone https://github.com/bistromath/gr-ais.git
 cd gr-ais
 mkdir build
 cd build
 cmake ../
 if you get an error at this point:
CMake Error at CMakeLists.txt:114 (find_package):
  Could not find a configuration file for package "Gnuradio" that is
  compatible with requested version "3.7.6".


then edit cmake to force 3.75 (a bodge, but works!):

cd ~/gr-ais
nano CMakeFiles.txt

find the section #Find gnuradio build dependencies
edit the line:
find_package(Gnuradio "3.7.6" REQUIRED)
change to

find_package(Gnuradio "3.7.5" REQUIRED)


 exit nano(Ctrl-x -->y-->enter)
 
resume with building:

cd ~/gr-ais/build
cmake ../
make
 sudo make install
 sudo ldconfig


if you get an error
ImportError: No module named ais_swig
then check you have installed swig, reboot and then re-try the steps to build gr-ais

Install and run "kal" :

mkdir ~/src
cd ~/src
sudo apt-get install libtool autoconf automake libfftw3-dev
git clone https://github.com/asdil12/kalibrate-rtl.git
cd kalibrate-rtl
git checkout arm_memory

./bootstrap
./configure
make
sudo make install

" to calibrate the RTL dongle to work out the error value to use in ais_rx
http://goo.gl/wbqOts. MY RTL dongle had an error of around minus 33 ppm, and this is the value passed to ais_rx below. replace with your error value. As the dongle warms up this value may change so check again after some time. don't forget to put an antenna on your SDR stick.
in the UK we have 900MH\ gsm base stations. for the US this is usually 850MHz. Command below is for 900MHz :

sudo kal -s 900

this will give you a channel number of a nearby GSM station

use the channel number to get a calibration value. e.g. below found chan: 114

sudo kal -c 114

this will then give you a ppm value -make note of it below
average absolute error: -33.163


profile your hardware by running the following command: (takes a long time!)
volk_profile

You can then pipe AIS messages to MarineTraffic using "socat" (sudo apt-get install socat) using the command below (where 1.2.3.4:1234 should be changed for your marinetraffic upload IP and port and --error -33 should be changed for your error value obtained from kal

ais_rx --gain 44 --error -33 -s osmocom | socat - UDP4-DATAGRAM:1.2.3.4:1234

if you run OpenCPN on a computer on your LAN, you can send the traffic to that at the same time as marinetraffic (assuming your OpenCPN computer is running on LAN 192.168.1.101:9999) and also pipe the raw AIS sentences to the console for confirmation of reception:
ais_rx --gain 44 --error -33 -s osmocom | tee >(socat - UDP4-DATAGRAM:1.2.3.4:1234) | tee >( socat - UDP4-DATAGRAM:192.168.1.101:9999)

to keep this running when you disconnect your console session, create a file and save the above commandline into it:
touch ~/ais.sh
sudo nano ~/ais.sh
paste the above commandline into file and save (Ctrl-x Ctrl-y)
make the file executable
sudo chmod +x ais.sh
Then to run as background process on startup, edit /etc/rc.local to have it run on startup)
sudo nano /etc/rc.local
paste the following line into it and save
/home/pi/ais.sh &

It is fairly processor-intensive on the Pi - 100% of two cores and 50-75% of the remaining cores.

I am no raspberry pi expert so optimisations could be made for sure. I'm happy to make my SD card image available to anyone who wants a copy, but I don't have sufficient hosting for the image file.

As the script runs headless on startup, no output is sent to the console by default.
To see it is working you can either
a) open up OpenCPN and see the traffic
b) sniff the network traffic on the destination computer using nc -l -n 192.168.1.101 9999 (linux)
c) sniff the network traffic using Wireshark (windows)
d) You can use rTail and pipe the output of the AIS parser to stream it to a webpage hosted on your Pi