Makersnake » Projects http://www.makersnake.com Mon, 01 Apr 2019 13:49:10 +0000 en-US hourly 1 http://wordpress.org/?v=4.1 Satellite communication with RockBLOCK http://www.makersnake.com/rockblock/ http://www.makersnake.com/rockblock/#comments Wed, 18 Feb 2015 09:00:02 +0000 http://www.ambglobal.com/?p=1 The RockBLOCK Mk2 is one awesome module. It literally houses everything you need to send and receive data from anywhere on the planet (Iridium satellite modem, compact antenna and power circuitry) in a module smaller than the Raspberry Pi (the de facto measuring implement for these kind of things) at an equally micro price of £159/€199/$269 – available to buy online from Rock 7

This product has already been widely adopted by the Arduino community, with many happy RockBLOCK’ers thanks to Mikal Hart’s C++ IridiumSBD library; but I couldn’t find anything specifically for the many Python Raspberry Pi users… Fear not, inspired by Mikal’s library, and copious amounts of Columbia’s finest, coffee that is, I’ve created… pyRockBLOCK. The super-simple library that makes sending and receiving messages via satellite as simple as: sendMessage(“Hello World”) and requestMessageCheck().

pyRockBLOCK will work on pretty much anything that runs Python; so you’ll be up and running with just a few lines of code, which will give you plenty of time to 3D print your very own Raspberry Pi X RockBLOCK case or create all manner of crazy UAV’s, High Altitude Balloons and Ocean Sensing Buoys using your RockBLOCK!

Related Makersnake Projects/Guides:

Part 1 – Raspberry Pi Setup (Software)

I’ve started off with a fresh installation of Raspbian – if you’re new to Raspberry Pi (where have you been hiding?) here’s a great starter guide to get your RPi up and running.

The first thing we’ll do is install some dependencies and a couple of useful tools; needless to say, ensure that your RPi has an internet connection so that these can be downloaded!

From the command line (running as root/sudo):

apt-get update

apt-get install python

apt-get install python-pip

pip install pyserial

apt-get install screen

apt-get install usbutils

apt-get install git

That’s everything installed – next we’ll clone the latest version of pyRockBLOCK from GitHub (https://github.com/MakerSnake/pyRockBlock)

cd /home/pi/

git clone https://github.com/MakerSnake/pyRockBlock
 

Part 2 – Raspberry Pi Setup (Wiring)

We’ve got two options when it comes to connecting the RPi to the RockBLOCK – via USB (using a USB to UART cable) or directly to the GPIO pins. Both are technically the same, so really just depends on your project or what cables you have laying around!

FTDI USB to UART cable converts 5V USB signals to 3.3V UART as well as providing 5V power to the module. 

The inline 6-way connector should be connected as below (Black to GND, Green to RTS)

wireWe ain’t got the power captain!

When the RockBLOCK is powered via USB at 5V it will draw a maximum of 450mA – it’s therefore important that your host (RPi) is itself connected to a good quality power supply that is capable of providing a reliable source of power.

Another important point, that caught me out, is that it’s essential that the FTDI USB to UART cable is configured to supply the required current (who knew you could configure a cable!). The FTDI cable used has an accompanying programming utility for setting the required current value.

After connecting the USB cable to the RPi it may take a few seconds for it to be detected; you can see if it has been recognised using: ls /dev/tty*

Screen Shot 2015-02-12 at 17.25.25

The device handle for your cable will vary depending on your cable/system – but typically if you’re using a USB/UART converter as described, it will normally include “USB” somewhere in the name (e.g. /dev/ttyUSB0 or /dev/tty.usbserial-FTH9I1S5)

If you’re not sure, or your’ve got multiple USB peripherals attached – try running the command with/without the peripheral connected and compare the results.

[checklist]

  • Make sure you make a note of your device handle, this will be required later!

[/checklist]

Another useful command is lsusb, which lists the USB peripherals connected to your device:

Screen Shot 2015-02-12 at 17.27.56

You can request more information, including the MaxPower value for your cable, using the following command: lsusb -v -d VENDOR:PRODUCT

Screen Shot 2015-02-12 at 17.30.51

The RPi can also be connected to the RockBLOCK directly using the GPIO pins, which is perfect if you need to use the USB ports for something else, or if you’re trying to reduce space. To make the connection between the two modules, you’ll need 4 or 5 jumper leads.

rock-pinsThe connections are fairly self-explanatory; simply connect 5V power (Red & Black) and the UART (Green & Blue) – if you wish to utilise the “Ring Alert” capability, make a final connection between GPIO 18 (or any you like) and the RI connection on the RockBLOCK.

When your RockBLOCK is permanently powered and undertaking regular satellite communications (at least once a day) it’s possible to receive “Ring Alerts”. This is a fantastic feature that will indicate when new messages are available, avoiding establishing a satellite session just to see if there are new messages. The RockBLOCK will set the “Ring Indicator” pin ON when a Ring Alert has been received from the satellite.

That’s the wiring complete, the final steps involve making some software configuration tweaks to your RPi.

Using your favourite editor (running as root/sudo), you’ll need to edit /boot/cmdline.txt to remove this text: console=/dev/ttyAMA01,115200 and kgdboc=ttyAMA,115200.

After editing your file should look something like this:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Next we need to edit /etc/inittab to comment out (add # at the start) the line that reads:

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt10 (For me this was the last line in the file)

Finally, reboot your RPi (using reboot command)

Your device handle for the RockBLOCK whilst connected via the UART will always be: /dev/ttyAMA0

  • Make sure you make a note of your device handle, this will be required later!

The Iridium modem requires a considerable amount of current whilst transmitting, that’s why you’ll notice the large “super capacitor” on the RockBLOCK. As such, it will take a while for the RockBLOCK to power up and begin to respond to commands (typically 60 seconds) whilst the capacitor is charging.

For more detailed information on the power usage profile of the RockBLOCK, and some pretty graphs, check out the official developer guide.

Before we start looking at the library, let’s first check that we can talk to the RockBLOCK; like most modems, the Iridium 9602 modem on the RockBLOCK has a plethora of AT commands to control it’s functionality. We’ll use the screen command (if you’re using a PC you can use PuTTY) to send commands to the modem and assess the response.

screen DEVICE HANDLE 19200 (e.g. screen /dev/ttyUSB0 19200 or /dev/ttyAMA0 19200)

NB: 19200 is the baud rate of the RockBLOCK

Now if you type AT and press [Enter], you should should see an OK response. If you don’t get any response, wait 30 seconds and try again – as mentioned above it may take 60 seconds for the RockBLOCK to fully power up and respond to commands.

To get out of screen press [Ctrl] + a, then press k, then press y (Not totally obvious – I had to Google it!)

 

Part 3 – Software Setup

Now that we’ve connected the RockBLOCK and confirmed that we can talk to it, we can start writing some code…. Unfortunately, there’s not much code to write, pyRockBLOCK does all the hard work for you and has been rigorously tested (it’s been hanging out my window, running my Remote Controlled Weather Station for the last three weeks!).

pyRockBLOCK provides super-simple commands enabling you to send and receive messages with just a few lines of code; without having to worry about the nitty-gritty of messing around with Serial Ports, AT commands, signal strength, calculating checksums, retry strategies or making the perfect coffee (only joking, it doesn’t do the latte, err doesn’t do the latter!).

If you are happy to embrace this black-box, skip the next few paragraphs and jump to the good stuff – else, if you’d like to know how all this magic works, grab a coffee and read on…

Mobile Originated (MO) messages (Sent from the RockBLOCK via Satellite)

Given that your RockBLOCK is tiny and has to communicate with a satellite up in space (781km away) that is zipping across the sky (at 27,000km/h) – it’s not always possible to get a reliable connection first time, as such the library facilitates an element retry.

When you try to and send a message the library will first query the signal strength from the modem (AT+CSQ). The signal strength is expressed on a 0 to 5 scale, where 0 is no signal, and 5 is perfect signal – just like the signal bars on your mobile/cell phone.

The signal strength is only updated every few seconds and is approximate, so even with a signal strength of 5 transmissions can still fail, conversely a signal strength of 1 can be acceptable for transmission. So really its just an approximate guide, that may, or may not be correct (insert pinch of salt here)!

For the library, i’ll consider that a signal strength of 2 to be acceptable to attempt to establish a satellite session – if the signal strength is less than this, we’ll go to sleep for a bit and then retry, this will occur a maximum of 10 times before permanently failing.

After verifying the signal strength, we’ll write the message to the modem’s output buffer (AT+SBDWB) and attempt then to initiate the satellite session (AT+SBDIX). If this fails, it often does, it will try again a maximum of 3 times automatically before permanently failing.

It will typically take 20-30 seconds to establish a satellite connection, but given the various levels of retry, I would only start to panic if this process takes more than a couple of minutes!

Mobile Terminated (MT) messages (Sent to the RockBLOCK via Satellite)

To receive a message on your RockBLOCK you’ll firstly need to request it from the satellite – messages will not be automatically “pushed” you need to “pull” it (like a cracker). 

When you request the library to check for messages, it will undertake the signal strength check (AT+CSQ) and attempt to establish a satellite session (AT+SBDIX) – if successful, your message will be downloaded (only one message can be downloaded in each satellite session).

The response from the satellite will indicate if there are additional messages to download; if there are additional messages “in the queue”, you’ll need to check for messages again; this will establish another satellite session, this should be repeated until there are no further messages in the queue.

pyRockBLOCK is built around a single module called rockBlock which is instantiated by providing a device handle string (e.g. /dev/ttyUS0) and a reference to your callback object. The callback object should extend the rockBlockProtocol class and implement the applicable methods (e.g. rockBlockConnected, rockBlockDisconnected, rockBlockMessageReceived etc).

Messages from the Raspberry Pi to RockBLOCK (MO)

This simple example connects to the RockBLOCK and attempts to send a message – rockBlockTxStarted is called to mark the start of the process,  and when the message has been successfully sent rockBlockTxSuccess will be called along with the “MOMSN”.  This is a unique message identifier for the transmission, you can search for this in the Rock 7 Core system. Alternatively, if the message fails to transmit rockBlockTxFailed will be called. Make sure that you call close to disconnect from the RockBLOCK.

import rockBlock

from rockBlock import rockBlockProtocol

class MoExample (rockBlockProtocol):
    
    def main(self):
      
        rb = rockBlock.rockBlock("/dev/ttyUSB0", self)
        
        rb.sendMessage("Hello World RockBLOCK!")      
        
	rb.close()
        
    def rockBlockTxStarted(self):
        print "rockBlockTxStarted"
        
    def rockBlockTxFailed(self):
        print "rockBlockTxFailed"
        
    def rockBlockTxSuccess(self,momsn):
        print "rockBlockTxSuccess " + str(momsn)
        
if __name__ == '__main__':
    MoExample().main()

 

Messages to the Raspberry Pi from RockBLOCK (via Space) (MT)

Receiving messages on your RockBLOCK is equally as simple – after you’ve queued a message with the satellites (using the Rock 7 Core, or the accompanying web-service) your message can be requested by the RockBLOCK by calling requestMessageCheck. This will attempt to establish a satellite session – if you’ve got a message, you’ll see a callback to rockBlockRxReceived with the unique message identifier (mtmsn) and the message payload (data) as a byte array.

You’ll also receive a callback to rockBlockRxMessageQueue, this will tell you how many (if any) additional messages are available to download. Remember, that you can only download one message per satellite session. Therefore, to get additional messages, you’ll need to call requestMessageCheck until count in rockBlockRxMessageQueue is zero. Make sure that you call close to disconnect from the RockBLOCK when you’re done.

import rockBlock

from rockBlock import rockBlockProtocol

class mtExample (rockBlockProtocol):
    
    def main(self):
        
        rb = rockBlock.rockBlock("/dev/ttyUSB0", self)
             
        rb.requestMessageCheck()
                                                                  
        rb.close()
           
    def rockBlockRxStarted(self):
        print "rockBlockRxStarted"
        
    def rockBlockRxFailed(self):
        print "rockBlockRxFailed"
        
    def rockBlockRxReceived(self,mtmsn,data):
        print "rockBlockRxReceived " + str(mtmsn) + " " + data
        
    def rockBlockRxMessageQueue(self,count):
        print "rockBlockRxMessageQueue " + str(count)
             
        
if __name__ == '__main__':
    mtExample().main()
 

That’s it – you can now send and receive messages from anywhere in the world!

To see pyRockBLOCK in action have a look at the Remote Controlled Weather Station project.

]]>
http://www.makersnake.com/rockblock/feed/ 43
Remote Controlled Weather Station http://www.makersnake.com/remote-controlled-weather-station/ http://www.makersnake.com/remote-controlled-weather-station/#comments Tue, 17 Feb 2015 16:02:21 +0000 http://www.makersnake.com/?p=155 Today we’ll be creating a remote controlled satellite weather station using a Raspberry Pi, a temperature sensor and a RockBLOCK. The envisioned application would be a weather station in a really remote location (i.e. outside of mobile/cellular coverage) – maybe in the middle of the desert, the jungle, or even the arctic – sending its data back to some kind of central weather system.

We’ll keep it really simple, using just one temperature sensor, but additional sensors could be added very easily to expand the scope – to measure humidity, atmospheric pressure or light levels. The temperature sensor used is a Maxim DS18B20 digital thermometer which provides a reasonably accurate reading (+/- 0.5 degrees) over a wide temperature range (-55 to +125C)

The weather station application will periodically transmit its sensor readings using the RockBLOCK. For those of you who don’t know the RockBLOCK, it’s an awesome little module that enables small amounts of data to be sent/received via satellite from anywhere in the world. Ideal for creating all manor of remotely deployed projects, like the weather station! We’ll be utilising the excellent pyRockBlock library (excellent, because it’s written by me!) to take care communicating with the satellites via the RockBLOCK.

The temperature sensor selected operates on the 1-Wire bus, which means it can be connected directly into the GPIO pins on the RPi, and with a little bit of configuration, can very easily be interrogated by Python – without the need for any additional electronics!

Part 1 – Wiring

The temperature sensor has three connections: positive, ground and signal – these should be connected to pins 1 (Blue), 4 (Yellow) and 7 (Green) respectively on the Raspberry Pi.

therm connectedThis module would normally require a pull-up resistor, but this can actually be configured with software with the Raspberry Pi, so no need to get your soldering iron out just yet! Be careful that you connect the sensor correctly, if for example you get the ground and positive mixed up, the sensor will get very hot very quickly!

There have already been many great tutorials on using the DS1B20 sensor with the RPi – but I initially struggled to see the sensor on the RPi. I thought, it’s got three wires, how hard could it be! I discovered, that there had been some changes made to Raspbian that required an additional configuration step to get it working correctly.

 

 

 

 

So on the RPi, using your favourite editor, edit /boot/config.txt to include the following line, just add it to the bottom of the file (make sure you edit the file as root/sudo).

dtoverlay=w1-gpio

Secondly, you’ll need to add the modprobe drivers for the 1-Wire system to the bottom of your /etc/modules file (again, running as root/sudo).

w1-gpio
w1-therm

Restart your RPi – you should now see two additional items in your startup log:

[info] Loading kernel module w1-gpio
[info] Loading kernel module w1-therm

If you’ve wired everything correctly, and the drivers have been loaded correctly, you should now be able to interrogate the sensor. The system will create a handle for the sensor in /sys/bus/w1/devices/ – there should be a sub-directory called 28-XXXXXXXXXXXX (e.g. 28-0000049b5484) – this is the unique handle to your sensor. It’s important to remember that each sensor is programmed during manufacture with a unique handle. Therefore you should never hardcode this value, it will change if you use a different sensor – you’ve been warned!

To read the current temperature sensor run the following:

cat /sys/bus/w1/devices/28-0000049b5484/w1_slave

You should see an output that looks something like this:

2a 01 4b 46 7f ff 06 10 16 : crc=16 YES
2a 01 4b 46 7f ff 06 10 16 t=18625

We’re only interested in the second line, and specifically the string t=18625 (this is the temperature) – to get decimal degrees value, simply divide this by 1000 = 18.625°C.

 

Part 2 – Software

If you’ve not done so already, follow the Satellite communications with RockBLOCK project to getting your RockBLOCK up and running.

Grab the latest copy of the Weather Station project from GitHub.

git clone https://XXX

I’ve created a simple class (temperatureBot) to query the sensor, get the raw reading and convert the value correctly into decimal degrees. This snippet prints the temperature every 10 seconds.

while(True):
            
	tb = temperatureBot.temperatureBot("/sys/bus/w1/devices/28-d9034234324")
            
	print tb.obtain()
            
	time.sleep(10)

But you said not to hardcode the sensor handle! Very observant of you – luckily the temperatureBot class provides some simple discovery logic to find your sensor automatically. If you provide None in the temperatureBot constructor, it will search your /sys/bus/w1/devices/ directory for the first sub-directory that starts 28-XXX. Obviously, this won’t work if you’ve got more than one sensor attached, nor if you’re using a different manufacturer, but should work well for most applications.

while(True):
            
	tb = temperatureBot.temperatureBot(None)
            
	print tb.obtain()
            
	time.sleep(10)

Now we’ve got our temperature reading, lets get it transmitted to the satellites.

Using pyRockBlock this can be achieved using the following method, which will transmit the current time and temperature. You’ll notice that i’ve added a prefix of “T” this is not essential, but it provides the scope for future enhancements, for example “T” could be replaced for “H” when sending the humidity etc.

def emit(self, value):
            
        rb = rockBlock.rockBlock("/dev/ttyUSB0", self)
        
        rb.sendMessage("T" + str( time.time() ) + ":" + str(value) )
                                                       
        rb.close()

I would recommend reading the pyRockBlock project guide, this will explain the satellite transmission steps in more detail, including the various callbacks to denote success or failure. Let’s combine the two methods and flesh out the project, i’ve introduced the SLEEP_INTERVAL variable, so that we can change this at runtime, as you’ll see in the next section…

import rockBlock
import time
import temperatureBot

from rockBlock import rockBlockProtocol

class Example (rockBlockProtocol):
    
    SLEEP_INTERVAL = 60
            
    def main(self):
        
        tb = temperatureBot.temperatureBot(None)
        
        while(True):
        
            value = tb.obtain()
            
            self.emit(value)
                        
            time.sleep( self.SLEEP_INTERVAL)
                                
    def emit(self, value):
            
        rb = rockBlock.rockBlock("/dev/ttyUSB0", self)
        
        rb.sendMessage("T:" + str( time.time() ) + ":" + str(value) )
                                                                                  
        rb.close()

As well as transmitting messages from the field, the RockBLOCK can also receive messages; this is especially useful for remotely deployed applications. For this project, we are going to setup the capability to remotely change the frequency for which temperatures are obtained and emitted.

I’ll explain how to actually send messages to the RockBLOCK in a minute, but firstly, I’d like to explain how the messages will come through pyRockBlock and into our application.

Given the nature of satellite communications, messages sent to the RockBLOCK are not “pushed” like an SMS, instead they need to be “pulled”, that is you must request the message from the satellite. So in order to check for messages, we must first establish a session with the satellite, this can be done in two ways, either by using the checkMessage command or by sending a message, using the sendMessage command.

As we are regularly transmitting messages (using the sendMessage command) there is no need to make additional calls to checkMessage; therefore, if we have a new message, it will be received when we transmit our temperature readings. The pyRockBLOCK library takes care of all the hard work, and simply makes a callback (to rockBlockReceived) when a message is received.

Below is the rockBlockReceived implementation for this project, i’ve devised a simple message format, enabling additional commands in the future. To change the frequency of the transmission to every 120 seconds, you would simply send a message of “F120

def rockBlockRxReceived(self,mtmsn,data):
                       
        if( str(data).startswith("F") ):
            
            newInterval = int( data[1:] )
                        
            #Frequency should be between 30 and 3000 seconds
            if(newInterval >= 30 and newInterval <= 3000):
                
                self.SLEEP_INTERVAL = newInterval
                
                print "New Interval " + str(newInterval)
                        
        else:
            
            print "Unknown Command Received"

 

So the complete Weather Station application would look like this:

import rockBlock
import time
import temperatureBot

from rockBlock import rockBlockProtocol

class Example (rockBlockProtocol):
    
    SLEEP_INTERVAL = 60
            
    def main(self):
        
        tb = temperatureBot.temperatureBot(None)
        
        while(True):
        
            value = tb.obtain()
            
            self.emit(value)
                        
            time.sleep( self.SLEEP_INTERVAL)
                                
    def emit(self, value):
            
        rb = rockBlock.rockBlock("/dev/ttyUSB0", self)
        
        rb.sendMessage("T:" + str(time.time()) + ":" + str(value) )
                                                                                  
        rb.close()
        
                
    def rockBlockRxReceived(self,mtmsn,data):
        print "rockBlockRxReceived " + str(mtmsn) + "/" + data + "/" + str( len(data) )
                        
        #F = Update Frequency e.g. F100 = Update transmission
        if( str(data).startswith("F") ):
            
            #Parse interval
            newInterval = int( data[1:] )
                        
            #Frequency should be between 30 and 3000 seconds
            if(newInterval >= 30 and newInterval <= 3000):
                
                self.SLEEP_INTERVAL = newInterval
                
                print "New Interval " + str(newInterval)
                        
        else:
            
            print "Unknown Command Received"

 

Sending/Receiving data from your Weather Station

Messages are sent/received to/from your RockBLOCK using the Rock 7 Core, or the accompanying web-service

For more detailed information on using the accompanying web-service, please check out the Rock 7 Core – Endpoints guide.

]]>
http://www.makersnake.com/remote-controlled-weather-station/feed/ 3
3D Printed Raspberry Pi X RockBLOCK enclosure http://www.makersnake.com/3d-printed-raspberry-pi-x-rockblock-enclosure/ http://www.makersnake.com/3d-printed-raspberry-pi-x-rockblock-enclosure/#comments Wed, 14 Jan 2015 15:37:19 +0000 http://www.makersnake.com/?p=109 This is a guide to making a 3D printed case etc

]]>
http://www.makersnake.com/3d-printed-raspberry-pi-x-rockblock-enclosure/feed/ 0
Idiots guide to Iridium http://www.makersnake.com/idiots-guide-to-iridium/ http://www.makersnake.com/idiots-guide-to-iridium/#comments Wed, 14 Jan 2015 15:12:53 +0000 http://www.makersnake.com/?p=94 iridiumThe Iridium satellite constellation is a mesh of low earth orbit satellites that move rapidly across the sky, providing truly global coverage anywhere on the planet. With a suitable satellite modem (like the Iridium 9602) that’s in the RockBLOCK, we can send and receive small amounts of data (a few hundred bytes) to/from your embedded system or computer. Iridium is used widely across many industries, it’s especially salient in military, shipping and logistics applications.

Iridium products work best with a clear view of the sky, but will work in more occluded locations (usually after a few attempts!)

Once you’ve sent a message from your RockBLOCK it will be brought back down to earth, via one of the Iridium Ground Stations. It will then be processed by the Rock 7 core system, which can be configured to automatically dispatch the message to your own web-server or e-mail address, all within a few seconds!

Whilst it’s cool that a Raspberry Pi connected to a RockBLOCK can send messages from your back garden;  it’s really cool when it’s bobbing up and down in the middle of the ocean.

I am by no means an Iridium expert, i’ve been dabbling with the technology (in the form of the RockBLOCK) for the last few years, with great success on both personal and professional projects.

Here are a few key points that i’ve learnt:

  • RockBLOCK != Mobile Phone
  • Iridium is super reliable and works anywhere in the world (its even used by the military)
  • Works best with a good view of the sky (i.e. outside), but will sometimes work inside
  • You are charged based on the amount of data transferred (typically a few pence/cents per 50 bytes sent)
  • By virtue of the above, it’s not possible to send photographs using the RockBLOCK
  • You can send 340 bytes at a time, or receive 270 bytes – so keep your messages short!
  • Messages are not “pushed” to the RockBLOCK you have to request them
  • It’s super simple to use with a Raspberry Pi

]]>
http://www.makersnake.com/idiots-guide-to-iridium/feed/ 0