SMS Feedback Point "Question Mark"

Introduction

As a means for demonstrating the SMS functionality of the Vodafone dongle driver for mbed, a simple illustrative concept was required. Inspired by seeing an Ethernet connected thermal receipt printer at IoT 7, we decided to connect a receipt printer to a Vodafone dongle and an mbed as a proof-of-concept.

Whilst the IoT 7 talk focused on the graphics library and online submission aspects being promoted, an interesting coincidence of the talk was that people could send messages to the thermal printer during it. After thinking for a while about where to put our printer, we asked ourselves "How about if the feedback element was *the focus* of the demo, rather than an aside?".

Thus, we fashioned a giant question mark out of old wooden flooring, attached the thermal printer to the "dot" section, and programmed it to print out SMS messages upon reception. Thus was borne the adhoc instant feedback point for anywhere gatherings:

/media/uploads/ashleymills/vfqm.jpg

From a pragmatic standpoint the demo illustrates the SMS functionality of the Vodafone K3770 dongle driver library for mbed. It is comprised of three components: the circuit; the software; and the physical form. These are described in the next sections.

Circuit layout

The circuit layout for the question mark is shown below.

/media/uploads/ashleymills/qmcl.jpg

The circuit consists of an mbed microcontroller and only two additional hardware components: (i) a Vodafone K3770 modem, (ii) an Adafruit thermal receipt printer.

The connection from the mbed to the thermal printer requires four different elements: the first two being 5V and GND for power, and the second two being transmit and receive lines of a TTL serial connection. Practically, it isn't really necessary to connect the transmit line unless status feedback is required from the printer, but it requires little extra effort. Note that the printer actually has two ground inputs as can be seen in the bottom left of the picture above.

  • The printer's TX and RX are connected to the mbed's pins 14 and 13 respectively which represent TTL RX and TX respectively for one of the mbed's three serial ports.
  • The Vodafone K3770 USB dongle has 4 wires: 5V and GND for power, and D+,D- for data signals.

WARNING: The USB dongle draws high peak currents during transmission and so is sensitive to the power supply. This may manifest as an inability to register, or function correctly. It is best practice to power the dongle from a reliable 5V power supply if possible, or alternatively to buffer the dongle power supply with a suitable capacitor.

Software component

The mbed program which drives the printer is multi-threaded and runs on the RTOS. The first thread scheduled by the RTOS is the standard c *main* function. From this, a thread is launched to control the printer. For pragmatic purposes, only the second thread is shown below. Please see the RTOS entry in the mbed cookbook for details on how to control threads.

VodafoneK3770 modem;                // <1>
AdafruitThermal printer(p13,p14);
printer.begin();

char numBuffer[20], msgBuffer[256]; // <2>
size_t numSMS;

while(true) { // <3>
   if(modem.getSMCount(&numSMS)!=OK) {
      if(numSMS>0) {
         if(modem.getSM(numBuffer,msgBuffer,256)==OK) {
            printer.print(msgBuffer);
            printer.feed(2);
         }
      }
   }
   Thread::wait(500);
}

1. Initialise objects

VodafoneK3770 modem;              
AdafruitThermal printer(p13,p14);
printer.begin();

The VodafoneK3770 modem object is constructed. Then the thermal printer object is constructed using mbed pins p13 and p13. The thermal printer is then initialised.

2. Allocate storage space

char numBuffer[20], msgBuffer[256];
size_t numSMS;

Space is allocated for the store the sender number in "numBuffer", for retrieved SMS messages in "msgBuffer", and for the number of SMS messages received in numSMS.

3. Receive-SMS-Print Loop

while(true) {
   if(modem.getSMCount(&numSMS)!=OK) {
      if(numSMS>0) {
         if(modem.getSM(numBuffer,msgBuffer,256)==OK) {
            printer.print(msgBuffer);
            printer.feed(2);
         }
      }
   }
   Thread::wait(500);
}

In overview the loop simply runs forever, retrieving items from the SMS queue and printing them. The printer is very trivial and simply prints whatever is sent to it. The printer library has additional functions for setting font tone and other properties of the printer. Let us step through the loop internals:

	if(modem.getSMCount(&numSMS)!=OK) {

Now we are getting into using the K3770 dongle library. This line retrieves the number of short messages in the dongle mailbox. It uses the getSMCount function:

int getSMCount(size_t *pCount) 

getSMCount takes a pointer to a size_t number variable, into which the number of short messages is stored. The function returns an integer indicating success or failure of the operation. Thus, the first line, both retrieves the number of SMS and checks that the call was successful.

      if(numSMS>0) {

If there are some SMS in the buffer, then continue.

         if(modem.getSM(numBuffer,msgBuffer,256)==OK) {

The library maintains a list of received message identifiers in a FIFO queue. The getSM function is used to retrieve messages from this queue. When the function is called, it retrieves the oldest message in the queue. It is specified as follows:

int getSM(char *number, char *message, size_t maxLength) 

The function takes three arguments: (i) number, a pointer to a character array into which the senders number is copied (ii) message, a pointer to a character array into which the SMS message is copied, and (iii) maxLength, the maximum number of characters that can be stored in the buffer including the terminating null character.

The function returns an integer indicating success or failure.

Thus the program line both retrieves the oldest message in the FIFO queue and checks for success of this operation.

            printer.print(msgBuffer);
            printer.feed(2);

Once the message is retrieved, it is simply sent to the receipt printer for printing. Following this, a couple of linefeed characters are sent so that the latest message will be separated from the last in the paper stream. In addition, the printer head is inside the printer, so in order to see the message a couple of line feeds are necessary.

   Thread::wait(500);

After printing the message, or if any of the above stages fail, then the thread just waits for 500ms.

That's it! The software then loops round again to check for further messages.

The full source code for the printer program can be found here:

Import program3GReceiptPrinter

Vodafone K3770 dongle enabled receipt printer.

Example messages

The printer has been used at a number of events, these are some of the, sometimes strange, messages it has received:

  • What does this say?
  • 12" quattro stagioni - no tomato
  • Why is the beer warm?
  • Be the trouble you want to see in the world.
  • I'm watching you.
  • How long is a piece of string?
  • Does this really work
  • Hello dave
  • This will self destruct in 5 seconds!
  • Where is Amelia?
  • Is it time for lunch?
  • What's with this guy and tomatoes?


1 comment on SMS Feedback Point "Question Mark":

24 Jan 2013

Does this works with K3771 ?

Please log in to post comments.