Makersnake http://www.makersnake.com Mon, 01 Apr 2019 13:49:10 +0000 en-US hourly 1 http://wordpress.org/?v=4.1 Sneak Peak at the new Apple Watch… http://www.makersnake.com/apple-watch/ http://www.makersnake.com/apple-watch/#comments Fri, 06 Mar 2015 08:25:47 +0000 http://www.makersnake.com/?p=397 Sneak Peak at the new Apple Watch…

]]>
http://www.makersnake.com/apple-watch/feed/ 0
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
Rock 7 Core for RockBLOCK users http://www.makersnake.com/rock-7-core-for-rockblock/ http://www.makersnake.com/rock-7-core-for-rockblock/#comments Fri, 16 Jan 2015 11:41:56 +0000 http://www.makersnake.com/?p=138 The Rock 7 Core system, is the online management system for your RockBLOCK. You can view messages sent from your RockBLOCK, send new messages as well as update your Endpoints for message delivery. It’s all very simple, but here is a quick overview…

After logging in you’ll be presented with a navigation menu on the left hand side, if you’ve got multiple RockBLOCK (as I do) you may have multiple devices/groups shown. Expand the menu until you can see your RockBLOCK (mine’s called RockBLOCK 8801).

Screen Shot 2015-02-16 at 11.32

Screen Shot 2015-02-16 at 11.25.23Clicking on the “Cog” icon against your device will bring up a menu; to view messages sent from your RockBLOCK, click on “Rock Block MO Messages” (MO means Mobile Originated according to Google).

 

 

 

 

 

 

 

On the screenshot below, you can see the the messages i’ve sent from my RockBLOCK (including the message payload – shown in orange).
Screen Shot 2015-02-16 at 11.26.48

Clicking on the “Send RockBLOCK MT Message” from the Cog menu, will enable you to send messages to the RockBLOCK (MT = Mobile Terminated).

Screen Shot 2015-02-16 at 11.27.12Pressing the “Submit MT Message” button will immediately queue your message with the satellites ready to be downloaded by your RockBLOCK next time it checks for messages.

 

Screen Shot 2015-02-16 at 11.25.41As well as viewing your messages in the Core, you can arrange for them to be automatically dispatched to a web-service (via HTTP POST request) or sent to an e-mail address. To configure your “Endpoints”, click the Cog icon on your “Group”, not your device – so on this screenshot my Group is called “RockBLOCK”.

Click on the option that says “Push API Endpoints”.

 

 

 

 

 

 

You can then enter your Endpoint address (you can have as many as you like). If you provide a URL, when a message is received from the RockBLOCK, it will be HTTP POST’ed to your server, along with details of the device and when the message was sent – full details, including parameter names are available in the official web-service documentation. Alternatively, if you select an e-mail address, the message will be automatically sent to your e-mail address, with the message payload included within the body of the e-mail, as well as an attachment.

Screen Shot 2015-02-16 at 11.26.12

 

]]>
http://www.makersnake.com/rock-7-core-for-rockblock/feed/ 0
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
Rock7 Core – Endpoints http://www.makersnake.com/rock7-core-endpoints/ http://www.makersnake.com/rock7-core-endpoints/#comments Sat, 10 Jan 2015 10:50:22 +0000 http://www.makersnake.com/?p=287 Following on from the Remote Controlled Weather Station project we’re going to investigate how data gets from your RockBLOCK to your web-server and vice versa. After reading this guide you’ll be fully armed to implement programatic two-way communications to/from your RockBLOCK.

Part 1 – Receiving Messages from your RockBLOCK

Data is sent from your RockBLOCK to one of the 66 earth-orbiting Iridium satellites - it’s brought back down to earth (via a ground station) and is routed to the Rock 7 Core system. It’s at this point that you can control how the data is dispatched, by defining one or more endpoints. (See the Rock 7 Core for RockBLOCK users’ guide for details on specifying these).

Don’t be daunted by the term endpoint, it simply refers to a location where data is sent (e.g. e-mail address or website URL). E-mail endpoints are very useful for debugging, but if you want to do anything more sophisticated, you’ll want to use a URL endpoint where you can in turn process or store the data – this is what we’ll be focusing on in this guide.

Data is sent to your endpoint as an HTTP POST request. For those of you who have dabbled with web-technologies will be familiar with the term; but for those who are new to this, I’ll explain… HTTP is the protocol used ubiquitously across the internet for sending/receiving data between client/server. The protocol defines a number of request methods, one of these is called POST. It’s typically used for submitting form-based data (e.g. when you enter your username and password to log in to a website) and takes the form of a key/value pair structure. So in this example, you’re submitting two parameters: username and password.

This is exactly how the data will sent to your endpoint, however instead of username and password you will receive a data parameter containing the bytes you’ve transmitted. You’ll also receive additional parameters, including a (very) approximate geographic location of your RockBLOCK (accuracy: typically several kilometres). Here is an excerpt from the RockBLOCK developer guide, detailing all the parameters:

parameters

Next you’ll need some kind of web hosting solution to host your endpoint to receive the requests. There are countless hosting providers, so i’ll leave it to you to find one that works best for you. Likewise, there are many programming languages available to implement your endpoint.  I’ve prepared examples in the most popular web-programming languages: Python, PHP, Java and Perl (it’s not really popular, but i’ve included it because I can). Each example demonstrates how to obtain the parameter values, decode the data parameter and send a suitable response.

import cgi

form = cgi.FieldStorage()


imei = form["imei"]
momsn = form["momsn"]
transmit_time = form["transmit_time"]
iridium_latitude = form["iridium_latitude"]
iridium_longitude = form["iridium_longitude"]
iridium_cep = form["iridium_cep"]
data = form["data"]

decoded = data.decode("hex")

print "Content-Type:text/html\n\n"
print "OK"
$imei = $_POST["imei"];
$momsn = $_POST["momsn"];
$transmit_time = $_POST["transmit_time"];
$iridium_latitude = $_POST["iridium_latitude"];
$iridium_longitude = $_POST["iridium_longitude"];
$iridium_cep = $_POST["iridium_cep"];
$data = $_POST["data"];

$decoded = pack('H*', $data);

echo "OK";
public class RockBlockServlet extends HttpServlet {

	protected void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String imei = request.getParameter("imei");
		String momsn = request.getParameter("momsn");
		String transmit_time = request.getParameter("transmit_time");
		String iridium_latitude = request.getParameter("iridium_latitude");
		String iridium_longitude = request.getParameter("iridium_longitude");
		String iridium_cep = request.getParameter("iridium_cep");
		String data = request.getParameter("data");

		response.getWriter().println("OK");

	}
}
#!/usr/bin/perl

use strict;
use CGI qw(param);

my $imei = param("imei");
my $momsn = param("momsn");
my $transmit_time = param("transmit_time");
my $iridium_latitude = param("iridium_latitude");
my $iridium_longitude = param("iridium_longitude");
my $iridium_cep = param("iridium_cep");
my $data = param("data");

print “Content-Type:text/html\n\n”
print “OK”;

What is hex-encoding?
Data sent from the RockBLOCK will be passed to your endpoint as a hex-encoded string. If you were to send the string MS - it would be converted into its hexadecimal value (ASCII / Latin-1 encoded) as 0x4D53, this will be sent to your endpoint stringwise as “4D53“. Likewise, if you were to send the string Makersnake, the string “4d616b6572736e616b65” would be received. The website string-functions.com provides handy tools for converting to/from hex-encoded strings.


Important
It’s essential that you respond quickly (within a couple of seconds) to requests; if you don’t the delivery is considered to have failed. This will result in further delivery attempts until a successful response is received. An acknowledging response is considered to be anything that has a HTTP 200 status code, so simply outputting OK will be sufficient.

I found this out the hard way: Whilst developing my remote controlled weather station project, I was sending an e-mail each time a request was received; which worked fine most of the time, except when my mail server responded slowly. This had the knock on effect that my acknowledging response was not sent for several seconds. As a consequence, the delivery was considered a failure and the same message was subsequently redelivered several times! (Thanks to splendid Rock 7 Support for helping me with this!)

 

Part 2 – Sending messages to your RockBLOCK

As you’ll recall from the Remote Controlled Weather Station project, we implemented a mechanism to remotely update the transmission frequency; by sending F:XXX the update frequency will be changed to XXX seconds.  Sending messages works the same way, except you send the HTTP POST request to the Core (instead of receiving requests from the Core).

HTTP POST requests are sent to: https://core.rock7.com/rockblock/MT with the following parameters:

imei – your unique identifier for your RockBLOCK (15 digits long, starting 30023)
username/password – your Rock 7 Core login credentials
data – the hex-encoded message (e.g. Hello = 48656c6c6f)

If the request has been successful, you’ll get a response like this: OK, XXXXXXXX  (Whereby, XXXXXXXX is a unique identifier for your message)

If there is a problem, for example message is too long, or you’ve got insufficient credits then the web-service will response as below:

FAILED, XX, YYYYYY  (Whereby, XX is the error code and YYYYYY is a human readable explanation of the error).

A full listing of the response codes can be found in the official RockBLOCK documentation.

Here are some examples of how you’d programatically send the message “F:100″ (463a313030) to your RockBLOCK.

Python

import urllib
import urllib2

url = 'https://core.rock7.com/rockblock/MT'
values = {'imei':'300230000000000', 'username':'makersnake', 'password':'secret', 'data':'463a313030'}

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
responseString = response.read()

PHP

request = new HttpRequest("https://core.rock7.com/rockblock/MT", HttpRequest::METH_POST);

$request->addPostFields(array('imei'=>'300230000000000', 'username'=>'makersnake', 'password'=>'secret', 'data'=>'463a313030'));

$response = $request->send()

$responseString = response->getBody();

Java

HttpClient agent = HttpClients.createDefault();
HttpPost request = new HttpPost("https://core.rock7.com/rockblock/MT");

List params = new ArrayList(4);

params.add(new BasicNameValuePair("imei", "300230000000000"));
params.add(new BasicNameValuePair("username", "makersnake"));
params.add(new BasicNameValuePair("password", "secret"));
params.add(new BasicNameValuePair("data", "463a313030"));

request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpResponse response = agent.execute(request);

HttpEntity entity = response.getEntity();

Perl

#!/usr/bin/perl

use LWP::UserAgent;

my $agent = LWP::UserAgent->new;

my $req = HTTP::Request->;new(POST=>; "https://core.rock7.com/rockblock/MT");

my $values = {'imei':'300230000000000', 'username':'makersnake', 'password':'secret', 'data':'463a313030'};

$req->content($values);

my $response = $agent->request($req);

my $responseString = $response->decoded_content;

 

]]>
http://www.makersnake.com/rock7-core-endpoints/feed/ 9
Merry Christmas from Makersnake http://www.makersnake.com/merry-christmas/ http://www.makersnake.com/merry-christmas/#comments Thu, 25 Dec 2014 12:00:48 +0000 http://www.makersnake.com/?p=97 Hopefully Santa brings you that 3D printer, Raspberry Pi or Arduino that you’ve been asking for…

]]>
http://www.makersnake.com/merry-christmas/feed/ 0
Driverless cars… sooner than you think… http://www.makersnake.com/driverless-cars/ http://www.makersnake.com/driverless-cars/#comments Tue, 14 Jan 2014 15:58:11 +0000 http://www.makersnake.com/?p=126 http://www.makersnake.com/driverless-cars/feed/ 0