Monthly Archives: July 2014

Sending, Receiving SMS messages with GSM Modem

Recently I bought an instance of adafruit’s SIM800 breakout board ‘fona’. This board allows for sending and receiving of SMS  text messages (and a lot of other functionality, of course. But I covered only the text messages for scratch). For the text messages, I added an adapter for my scratchClient software.
For download and documentation, see [url][/url]

In scratch, a variable ‘sms_out’ is used to send messages, incoming messages are in the sensor value ‘sms_in’. Easy to use, and today I ignored provider cost and have sent me SMS every hour ‘scratch installation still running’. Could be more useful, but is fun when your computer gives you a call.

Connection of fona is by RX, TX to TX, RX of raspberry. You need to remove some getty processes from this line, there are documentations around describing this.

The sim800 uses an AT-protocol, like ‘at+cpin?’, and receives signals like ‘+CPIN: SIM PIN’.
For the initialization of the device, the adapter implements a state machine, which step by step initializes the modem, sets the pin and then waits for action.
Switching the modem on is done by pressing the ‘on’ key on the breakout board. Could be done by using GPIO, but I decided to need some additional access control.

The receiver side oft the serial protocol reads line by line, looks for known names and feeds the state machine with input.

The code is still experimental. There is no buffering for scratch input, so if scratch feeds too fast, there will be lines dropped. But It is not intended as a spam machine… The phone number being called on send events is fixed for the same reason.

If you want to run the software, be sure to have a backup phone which allows to reset the pin (in case it was forgotten to configure the pin in the adapters xml file, it might happen that after a few retries the device is blocked.)
And the manual of the sim800 is useful. Which is 300 pages.


Scratch Connection Status Display

With a new adapter adapter.gpio.GpioStateOutput, it is possible to bring the scratch connection state to GPIO.

When scratchClient is started, the associated GPIO pin is going high. When connection to scratch is established, the pin is blinking slowly. And when scratchClient is terminated, the GPIO is going low.
Just add the configuration für this adapter to your configuration.

    <adapter class='adapter.gpio.GpioStateOutput'  name='state'>
        <description>State display on IKG.IO.9</description>

        <gpio port='IKG.IO.9' alias='state'>
            <default dir='OUT'  default='low' />
            <active  dir='OUT'  default='low' />

Please note the naming of the port: these names are configurable. You could use GPIO04 instead, or P1-07 if you prefer board numbering.
For my school workshop, there is an extra LED available, connected all the time, but not used for other IO. This LED sits on the adapter board in a corner and is ideally suited for a state display.