SMS Controlled relay

I've finally soldered my Ericsson T29s on to wires, for connecting the mbed!
Now i'll try out the commands for sending, reading and deleting SMS, using the "Serial pass-through" example.
Next is:

1: Reading SMS, converting PDU to ASCII, for my eyes to read.

2: Controlling one or more relays, according to the SMS you send.

3: At last, making it read a DS18B20 Temperature sensor, as this is gonna be a heat-controlling device.

 

T29s to mbed

 

Any suggestions about the project is most welcome!

 

15. Jan. 2010:
I've deleted the polish code. Here's my own so far (with help from Igor):

/*
Author: Christian Lerche
Date: 15-01-2010
MCU: LPC1768
Notes: SMS controlled relay
*/
#include "mbed.h"

DigitalOut led(LED1);
Serial pc(USBTX, USBRX); // tx, rx of USB
Serial device(p9, p10);  // tx, rx of RS232 pins
unsigned char buf[50];
unsigned int i;

void rec() {                                             // Here's my serial interrupt routine.  
    buf[i]=device.getc();                                // Put the character received into the buffer, at place "i"
    i++;                                                 // Increment "i" to make ready for next interrupt
}                                                        // interrupt is done. 
            
int main() {                                             // Main structure. 
    wait(1);                                             // Wait 1 sec, to make sure phone is ready!
    device.printf("AT+CPMS=\"ME\",\"ME\",\"ME\"\r");     // Thanks to Igor for helping me out with quotes
    wait(3);                                             // Wait 3 sec
    device.attach(&rec);                                 // Attach the "Rec" interrupt to the serial, so we receive every character. 
    device.printf("AT+CMGR=3\r");                        // Read the incoming message
    wait(3);                                             // Wait 3 sec to make sure we got it all from the cellphone. 
    if (buf[30]=='O' && buf[31]=='7') {                  // Again, Igor opened my mind here.
        led=1;                                           // if character is correct, turn on LED1
    }
    device.attach(0);                                    // Detach the interrupt function here, until reset has occured. 
    device.printf("AT+CMGD=3\r");                        // Send command to delete the third message in memory 
    for ( i=0; i<50; i++) {                              // Put the character received into the computer. 
        pc.putc(buf[i]);                                 // ^^
        }    
    for ( i=0; i<50; i++) {                              // Delete whats in the buffer (making it ready for a loop, for reset to be unnessesary 
        buf[i]=0;                                        // ^^    
    }
    wait(3);                                             // wait command, to make ready for loop
}

By now, it reads the message, but I have to write som code, for reading the last bytes of my buf-array.

I see that I need more buffer. I will try the Serialbuffered.
Instead of serialbuffered, I used the serial.attach function. Cannot test code right now, I'm at work.
Now it should read the characters from the phone to the buffer, and then to the computer, hooked with HyperTerminal.
I hope it works.


4 comments

12 Jan 2010

You can use \ to escape quotes:

device.printf("AT+CPMS=\"ME\",\"ME\",\"ME\"\r");

You can also use characters instead of hex numbers:

if (buf[30]=='O' && buf[31]=='7')
led=1;

12 Jan 2010

Igor:

Really appreciate you taking the time to write comments!! Thanks a billion!

/ Lerche

15 Jan 2010

A similar project would be hooking up MBED with a 3G USB modem and maybe featuring a local web server as well.

15 Jan 2010

It sure would, but I would have to sign a subscription.
As it is actually a project for a colleague of mine, and it's supposed to turn on a heater in Sweden, he uses a prepaid SIM. (We both live in Denmark)

You need to log in to post a comment