Introduction: LinkIt ONE - Sending Personalized SMS to a Group of People

About: I may be an electrical engineer by trade but that won't stop me from tinkering in the domain of mechanical engineers and artists:P

I am throwing a big party in a few weeks and I want all my friends to come. I can't make a post on facebook because I don't want random people I friended anywhere near my place, I know many of my friends don't check their email, letters are expensive... SMS! I have all their phone numbers, I can invite them via SMS! But wait... I can't send them just a generic SMS... I want it to be personalized! But writing 100+ SMS isn't exactly what I want...

Luckily I have a Mediatek's LinkIt ONE board and enough programming skills to automate it all.

This Instructable will teach you how to send personalized SMS to as many people as you want using nothing but a LinkIt ONE board and a PC with Python and PySerial installed.

Step 1: How It Works

LinkIt ONE must be running code which reads remote number and text from serial port and sends SMS.

Python, running on your PC will read message.txt for message content, fill the gaps with details from data.csv and tell LinkIt ONE what and to who SMS must be sent.

Sounds easy but there are quite a few obstacles on both python and LinkIt ONE side to be dealt with.

Step 2: Python

I won't go in detail about the Python part as I have discussed it in detail in my other Ible and it is well commented if you take a look at attached code. I will only explain what you need to know to use it.

You must put two files in same folder as python code is. Those are "message.txt" and "data.csv".

message.txt contains message which you want to send to everybody and should contain "flags" which will be used to fill in correct data (in square parenthesis: [flag]).

data.csv should be created in spreadsheet editor such as excel and exported to .csv format (data separated by ";" ). First line must contain flags (names of flags as used in message.txt but without square parenthesis) and following lines must contain data. Note that first column must contain phone numbers only.

As an example, I will show you how message.txt and data.csv should look like if you wanted to invite a bunch of friends and their partners to come to your party.


data.csv

phone namepartner
123456789JonhLilli
987654321AliceTerry


message.txt

Hi, [name],
I am throwing a big party this Christmas and would be glad if you and [partner] could make it. It 'll be the best!
Please confirm if you come.
Best,
ptkrf


I believe you won't have any trouble modifying those two files to suit your needs. data.csv may be ordered in any way so long as first column contains phone numbers and first row contains correct flags. Keep in mind that message with all data filled in must not exceed SMS length limit - 140 characters or sending will fail.

Step 3: LinkIt ONE

The code isn't complicated but unlike with sending only one SMS, when you are sending a bunch, it is very important to set up a confirmation loop and break the program if something goes wrong. Luckily LinkIt ONE's LSMS library replies with 1 for success and 0 for failure so error checking isn't hard to implement. As seen in code below, function can be executed as a parameter of Serial.println - Serial.println(LSMS.endSMS())

#include 
//-------------------------------------------
void setup() {
  Serial.begin(9600);
  //wait for serial comm to be established
  while(!Serial){;}
  Serial.println("ready");
}
//-------------------------------------------

String text="";
bool textReady = false;
String remoteNumber;    
char* num;
//-------------------------------------------
void loop() {
  while (!textReady){
    parse();
  }
  
  textReady = false;
  remoteNumber = text;
  //following function must e used because LSMS.beginSMS()
  //requires charArray as parameters and not a String
  text.toCharArray(num, text.length());
  text = "";

  //-------------------------------------------
  while (!textReady){
    parse();
  }

  textReady = false;
  //feedback for troubleshooting
  //may be removed but then you won't know what went wrong
  //if code stops
  Serial.print("sending to: ");
  Serial.println(remoteNumber);
  Serial.print("msg: ");
  Serial.println(text);
  
  LSMS.beginSMS(num);
  LSMS.print(text);
  Serial.println(LSMS.endSMS());
  //ends SMS and returns confirmation (1 OK, 0 fail)
  
  text = "";
}
//-------------------------------------------
//saves all text until carridge return in "txt" variable
//-------------------------------------------
void parse(){
  while(Serial.available()){
    char tmp = Serial.read();
    if (tmp=='\r'){
      //Serial.println(text);
      textReady = true;
    }
    text += (char)tmp;
  }
}

Step 4: Making It Work

insert a SIM card in LinkIt ONE board, attach GSM antenna, upload the code and run Python script. Keep in mind that message.txt and data.csv must be in same folder as Python script.

This exact same code works on Windows, Mac and Linux, if you manage to install LinkIt drivers.

Have fun, send group SMS' and see stay tuned for next 'Ible.