<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: sms code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 21:55:24 GMT</pubDate>
    <description>DZone Snippets: sms code</description>
    <item>
      <title>Sending/Receiving SMS from MIDlets</title>
      <link>http://snippets.dzone.com/posts/show/5115</link>
      <description>&lt;code&gt;&lt;br /&gt;// Lets send an SMS now.&lt;br /&gt;//get a reference to the appropriate Connection object using an appropriate url&lt;br /&gt;MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");&lt;br /&gt;//generate a new text message&lt;br /&gt;TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);&lt;br /&gt;//set the message text and the address&lt;br /&gt;tmsg.setPayloadText(message);&lt;br /&gt;tmsg.setAddress("sms://" + number);&lt;br /&gt;//finally send our message&lt;br /&gt;conn.send();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// Time to receive one.&lt;br /&gt;//get reference to MessageConnection object&lt;br /&gt;MessageConnection conn = (MessageConnection) Connector.open("sms://:50001");&lt;br /&gt;//set message listener&lt;br /&gt;conn.setMessageListener(&lt;br /&gt;   new MessageListener() {&lt;br /&gt;      public void notifyIncomingMessage(MessageConnection conn) {&lt;br /&gt;         Message msg = conn.receive();&lt;br /&gt;         //do whatever you want with the message&lt;br /&gt;         if(msg instanceof TextMessage) {&lt;br /&gt;            TextMessage tmsg = (TextMessage) msg;&lt;br /&gt;            System.out.println(tmsg.getPayloadText());&lt;br /&gt;         } else if(msg instanceof BinaryMessage) {&lt;br /&gt;            .....&lt;br /&gt;         } else {&lt;br /&gt;            ......&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 07 Feb 2008 11:44:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5115</guid>
      <author>umut.utkan (Umut Utkan)</author>
    </item>
    <item>
      <title>Send and receive SMS text messages with Ruby and a GSM/GPRS modem</title>
      <link>http://snippets.dzone.com/posts/show/3647</link>
      <description>&lt;code&gt;require 'serialport'&lt;br /&gt;require 'time'&lt;br /&gt;&lt;br /&gt;class GSM&lt;br /&gt;  &lt;br /&gt;  SMSC = "+447785016005"  # SMSC for Vodafone UK - change for other networks&lt;br /&gt;&lt;br /&gt;  def initialize(options = {})&lt;br /&gt;    @port = SerialPort.new(options[:port] || 3, options[:baud] || 38400, options[:bits] || 8, options[:stop] || 1, SerialPort::NONE)&lt;br /&gt;    @debug = options[:debug]&lt;br /&gt;    cmd("AT")&lt;br /&gt;    # Set to text mode&lt;br /&gt;    cmd("AT+CMGF=1")&lt;br /&gt;    # Set SMSC number&lt;br /&gt;    cmd("AT+CSCA=\"#{SMSC}\"")    &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def close&lt;br /&gt;    @port.close&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def cmd(cmd)&lt;br /&gt;    @port.write(cmd + "\r")&lt;br /&gt;    wait&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def wait&lt;br /&gt;    buffer = ''&lt;br /&gt;    while IO.select([@port], [], [], 0.25)&lt;br /&gt;      chr = @port.getc.chr;&lt;br /&gt;      print chr if @debug == true&lt;br /&gt;      buffer += chr&lt;br /&gt;    end&lt;br /&gt;    buffer&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def send_sms(options)&lt;br /&gt;    cmd("AT+CMGS=\"#{options[:number]}\"")&lt;br /&gt;    cmd("#{options[:message][0..140]}#{26.chr}\r\r")&lt;br /&gt;    sleep 3&lt;br /&gt;    wait&lt;br /&gt;    cmd("AT")&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  class SMS&lt;br /&gt;    attr_accessor :id, :sender, :message, :connection&lt;br /&gt;    attr_writer :time&lt;br /&gt;    &lt;br /&gt;    def initialize(params)&lt;br /&gt;        @id = params[:id]; @sender = params[:sender]; @time = params[:time]; @message = params[:message]; @connection = params[:connection]&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def delete&lt;br /&gt;      @connection.cmd("AT+CMGD=#{@id}")&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def time&lt;br /&gt;      # This MAY need to be changed for non-UK situations, I'm not sure&lt;br /&gt;      # how standardized SMS timestamps are..&lt;br /&gt;      Time.parse(@time.sub(/(\d+)\D+(\d+)\D+(\d+)/, '\2/\3/20\1'))&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def messages&lt;br /&gt;    sms = cmd("AT+CMGL=\"ALL\"")&lt;br /&gt;    # Ugly, ugly, ugly!&lt;br /&gt;    msgs = sms.scan(/\+CMGL\:\s*?(\d+)\,.*?\,\"(.+?)\"\,.*?\,\"(.+?)\".*?\n(.*)/)&lt;br /&gt;    return nil unless msgs&lt;br /&gt;    msgs.collect!{ |m| GSM::SMS.new(:connection =&gt; self, :id =&gt; m[0], :sender =&gt; m[1], :time =&gt; m[2], :message =&gt; m[3].chomp) } rescue nil&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;destination_number = "+44 someone else"&lt;br /&gt;&lt;br /&gt;p = GSM.new(:debug =&gt; false)&lt;br /&gt;&lt;br /&gt;# Send a text message&lt;br /&gt;p.send_sms(:number =&gt; destination_number, :message =&gt; "Test at #{Time.now}")&lt;br /&gt;&lt;br /&gt;# Read text messages from phone&lt;br /&gt;p.messages.each do |msg|&lt;br /&gt;  puts "#{msg.id} - #{msg.time} - #{msg.sender} - #{msg.message}"&lt;br /&gt;  # msg.delete&lt;br /&gt;end&lt;/code&gt;</description>
      <pubDate>Thu, 08 Mar 2007 11:41:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3647</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>PyS60 - listSMS to File.txt</title>
      <link>http://snippets.dzone.com/posts/show/3042</link>
      <description>// Salva la lista degli SMS in un file&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from time import ctime&lt;br /&gt;&lt;br /&gt;import codecs&lt;br /&gt;import inbox&lt;br /&gt;&lt;br /&gt;box = inbox.Inbox()&lt;br /&gt;msg = box.sms_messages()&lt;br /&gt;&lt;br /&gt;f = codecs.open('E:/Others/listSMS.txt', 'w', 'utf8') # Apre il file in codifica UTF8&lt;br /&gt;for i in msg:&lt;br /&gt;	f.write(box.address(i))&lt;br /&gt;	f.write('\n')&lt;br /&gt;	f.write(ctime(box.time(i))) # Converte i secondi in una stringa rappresentante il tempo&lt;br /&gt;	f.write('\n')&lt;br /&gt;	f.write(box.content(i))&lt;br /&gt;	f.write('\n')&lt;br /&gt;f.close()&lt;br /&gt;&lt;br /&gt;print 'Fine'&lt;br /&gt;&lt;br /&gt;f = codecs.open('E:/Others/listSMS.txt', 'r', 'utf8')&lt;br /&gt;print f.read()&lt;br /&gt;f.close()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 27 Nov 2006 00:52:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3042</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Python - SendSMS over BT and AT</title>
      <link>http://snippets.dzone.com/posts/show/3041</link>
      <description>// Send SMS over Bluetooth (AT Command)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import bluetooth&lt;br /&gt;&lt;br /&gt;sockfd = bluetooth.BluetoothSocket(bluetooth.RFCOMM)&lt;br /&gt;sockfd.connect(('00:00:00:00:00:00', 1)) # BT Address&lt;br /&gt;sockfd.send('ATZ\r')&lt;br /&gt;sockfd.send('AT+CMGF=1\r')&lt;br /&gt;sockfd.send('AT+CSCA="+393359609600"\r') # Client TIM ITA&lt;br /&gt;sockfd.send('AT+CMGS="+39xxxxxxxxxx"\r') # TO PhoneNumber&lt;br /&gt;sockfd.send('Messaggio da mandare...\n')&lt;br /&gt;sockfd.send(chr(26)) # CTRL+Z&lt;br /&gt;sockfd.close()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 26 Nov 2006 21:31:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3041</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Read SMS with inbox module</title>
      <link>http://snippets.dzone.com/posts/show/1331</link>
      <description>The new pys60 (1.3.1) provide 'inbox' module to read SMS.&lt;br /&gt;It can also notify you when a new message arrives.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; import inbox&lt;br /&gt;&gt;&gt;&gt; i = inbox.Inbox()&lt;br /&gt;&gt;&gt;&gt; m = i.sms_messages()  # all message ID's&lt;br /&gt;&gt;&gt;&gt; i.content(m[0])     # first message&lt;br /&gt;u&#8217;foobar&#8217;&lt;br /&gt;&gt;&gt;&gt; i.time(m[0])&lt;br /&gt;1130267365.03125&lt;br /&gt;&gt;&gt;&gt; i.address(m[0])     # Only name is given :(&lt;br /&gt;u&#8217;John Doe&#8217;&lt;br /&gt;&gt;&gt;&gt; i.delete(m[0])&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;I wish the i.address gave more detail information.&lt;br /&gt;Currently, if you need the number, you need to search&lt;br /&gt;the &lt;a href=http://bigbold.com/snippets/posts/show/379&gt;contact database&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;See an example of notification callback in the documentation.</description>
      <pubDate>Wed, 01 Feb 2006 08:41:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1331</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Sending sms from nokia series 60</title>
      <link>http://snippets.dzone.com/posts/show/120</link>
      <description>I am really impressed by this.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import messaging&lt;br /&gt;messaging.sms_send(number, text)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Apr 2005 03:26:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/120</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
