The following example shows how to use the HTTP POST option for sending a Mobile Terminated (MT) message to the RockBLOCK modem. See the RockBLOCK Web Services User Guide for more information. It also shows how to use the CircuitPython library to receive that message at the modem.
This is an example of sending a Mobile Terminated (MT) message to the modem.
Generating a HTTP POST can be done in numerous ways:
- use curl from the command line
- use the requests module in Python
- similar options in Ruby, PHP, JavaScript, etc.
- enter URL in a web browser
The basic HTTP POST URL is:
https://rockblock.rock7.com/rockblock/MT?imei=IMEI&username=USERNAME&password=PASSWORD&data=DATA
where the four required parameters are:
- IMEI = The unique IMEI of your RockBLOCK modem
- USERNAME = Your Rock 7 Core username
- PASSWORD = Your Rock 7 Core password
- DATA = The message (hex encoded)
Account user name and password information must be included in the URL. Be careful not to expose these.
Finding the IMEI Number
To find the IMEI number for your RockBLOCK modem, first log in to your account. Once logged in, select the My RockBLOCKs tab in the left hand menu. The IMEI number will be shown for each RockBLOCK in the list.
Hex Encoded Data
The data being sent to the modem must be in the form of raw bytes, with each byte represented by its hex value. For example, if you want to send "hello world", it won't work to have:
data="hello world"
Instead, the text must be converted. In Python, the hexlify() command in the binascii module can be used. The text string must also be converted to bytes before sending to hexlify(). This can be done using encode() or via the b prefix to indicate raw bytes.
>>> import binascii >>> DATA = binascii.hexlify(b'hello world') >>> type(DATA) <class 'bytes'> >>> DATA b'68656c6c6f20776f726c64' >>>
So the resulting data parameter in the URL would look like:
data=68656c6c6f20776f726c64
Final URL Example
There's no way to show a complete URL example without revealing secrets. But a representative URL to send "hello world" to a RockBLOCK modem would look something like:
https://rockblock.rock7.com/rockblock/MT?imei=123456789&username=foo&password=bar&data=68656c6c6f20776f726c64
The RockBLOCK online API reference includes a page that helps with generating the URL. It also provides code snippets for various programming languages:
Checking Messages
Once the HTTP POST has been successfully made, the message has been sent. It can be viewed in the Messages tab of the RockBLOCK admin page:
Sending this message consumed 1 credit.
Sending messages to the RockBLOCK modem with HTTP POST consumes credits!
Receiving Message with Modem
Once the message has been sent, it can be received via the RockBLOCK modem. The receive text example from the CircuitPython library can be used:
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # pylint: disable=wrong-import-position import time # CircuitPython / Blinka import board uart = board.UART() uart.baudrate = 19200 # via USB cable # import serial # uart = serial.Serial("/dev/ttyUSB0", 19200) from adafruit_rockblock import RockBlock rb = RockBlock(uart) # try a satellite Short Burst Data transfer print("Talking to satellite...") status = rb.satellite_transfer() # loop as needed retry = 0 while status[0] > 8: time.sleep(10) status = rb.satellite_transfer() print(retry, status) retry += 1 print("\nDONE.") # get the text print(rb.text_in)
Here is the example output running the above example on a PC with the RockBLOCK modem attached via the USB-to-serial cable:
$python3 rockblock_recv_text.py Talking to satellite... 0 (32, 14, 2, 0, 0, 0) 1 (32, 14, 2, 0, 0, 0) 2 (32, 14, 2, 0, 0, 0) ... deleted output ... 80 (32, 14, 2, 0, 0, 0) 81 (32, 14, 2, 0, 0, 0) 82 (0, 14, 1, 2, 11, 0) DONE. hello world
The number of tries it takes to finally make satellite contact will depend on location and available sky view area. For the above test, the modem was placed in a window which also had several trees outside. The view of the sky was not great, but it still eventually was able to make contact - after 82 tries.
Text editor powered by tinymce.