more G-Labs products

Author Topic: Sending and Receiving SMS (Work in progress)  (Read 2653 times)

November 19, 2015, 03:44:49 PM
Read 2653 times

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
I've been knocking up some code in an attempt to be able to send and respond to text messages.

It needs a fair bit of work refactoring - and didn't really go as planned due to the serial port helper not really supporting raw reads, I don't know if the buffer is set quite small, but it was still splitting messages unexpectedly.

Anyway I am using a Siemens TC35 GSM Development board connected to the onboard rpi serial port (disable serial console through raspi-config)

What possibly would be good is to be able to send and receive messages without having event handlers.. and being able to track the status of the last command..

anyway comments welcome and I need to work out how to pass multiple values to a delegate / function.


December 04, 2015, 01:05:51 AM
Reply #1

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Now done a bit more work on this, and thanks to the pushingbox code, worked out how to send messages from other programs... so also a sample app sending messages attached too..

Can't guarantee it will work for anyone else but might as well share it :)

October 14, 2016, 09:23:50 PM
Reply #2

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34

October 14, 2016, 09:58:16 PM
Reply #3

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Will export my versions later

October 14, 2016, 10:04:29 PM
Reply #4

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
i will wait. i want to remove gammu and sms3 coz it sometime hang not repond, message receive but commannd not executed. i will share my script soon, but it fail i can find the message.

October 19, 2016, 10:31:28 AM
Reply #5

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Exported these from my system the other day, have changed logging since, will sort out getting these into github


November 16, 2016, 04:25:05 PM
Reply #6

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34

November 16, 2016, 04:41:35 PM
Reply #7

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
What hardware do you have for sending the messages and what OS? Or can you post your gammu conf

November 16, 2016, 09:41:59 PM
Reply #8

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
Debian wezzy, im uninstall gammu and sms tools 3. im use your script to send message. for sms remote i have no plan use gammu or sms tools 3 again. not work for me coz it some times hang sms receive but script if message receive not executed. try to use your script

i use raspbery pi b+ on, next may i will use rasp pi 3, for internet i use tplink with usb modem gsm 4g, i connect to lan on pi. and use duck ddns to acses it from internet.

modem for, sms wawei e173 conek to pi USB0

November 17, 2016, 11:54:43 AM
Reply #9

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Install the program, configure the options to be /dev/USB0 if that's what your usb modem is configured as..

you can then check the /usr/local/bin/homegenie/sms.log file to see what it is doing, if anything..

then try sending a text message to the number :)

November 18, 2016, 11:49:16 AM
Reply #10

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
Yes its work.
I mean how to use the command prosesor? im not programer, but try to learn and understand thats script.
I think the command processoe its like script to get the message from sms and execute some command.
Ex were if sender same with phone number on script, it will search some string on sms ex GPIO12-ON, if it found command processor will execute via web api to turn on the gpio 12. if not found command prosessor will text to sender with some text. Its command prosesor like that? if yes how to do with your script, explain give me some sample. very very need this  ;D


BTW i have modificate ur script from 1st version with this line
==============================================

while (Program.IsEnabled){
  if(!SerialPort.IsConnected){
    Log("Connecting to GSM Modem on port " + Program.Option("Port").Value);
    SerialPort
      .WithName(Program.Option("Port").Value)
      .OnStatusChanged(HandleStatusChanged)
      .OnMessageReceived(HandleMessageReceived)                       
      .OnStringReceived(HandleStringReceived)
      .Connect(9600);
   
    SerialPort.EndOfLine = "\r\n";
   
    Log("Initialising GSM Modem");
    Log("Turning local echo off");
    SendCommand("ATE0"); // Local Echo off
    Log("Switching to data mode");
    SendCommand("AT+CMGF=1"); // SMS Mode
    Log("Enabling message notifications");
    SendCommand("AT+CNMI=2,1,0,0,1"); // Enable Message Notifications   
   
    // Issue command to list any unread messages stored on the gsm modem (assume read = deleted)
    //Log("Getting any stored messages");
    //SendCommand("AT+CMGL=\"REC UNREAD\""); // Unread
    //SendCommand("AT+CSCS=\"PCCP437\""); // All
    SendCommand("AT+CPMS=\"SM\""); // All
    SendCommand("AT+CMGL=\"ALL\""); // All
    SendCommand("AT+CMGD=1,4"); // All
  }
  // Stop excessive cpu usage
  Pause(40);
  {
    // Issue command to list any unread messages stored on the gsm modem (assume read = deleted)
    //Log("Getting any stored messages");
    //SendCommand("AT+CMGL=\"REC UNREAD\""); // Unread
    //SendCommand("AT+CSCS=\"PCCP437\""); // All
    SendCommand("AT+CPMS=\"SM\""); // All
    SendCommand("AT+CMGL=\"ALL\""); // All
    SendCommand("AT+CMGD=1,4"); // All
  }
  Pause(40);
}
Program.GoBackground();

=======================================================
Tts works and auto check then get the message. with your original version its fail to get new message, so i modificate like thats.

Your second update i have some missing error report, if gsm sim not inserted message error with CME ERROR not shown, not like 1st version.
Try to search whats the problem.
But i think its not some big problem, coz the sender working normaly.

 Good Job Sir  ;) :) ;D

November 18, 2016, 12:19:02 PM
Reply #11

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
ok,

wrote a reply and lost it.. damn web browser:

This code specifies the commands you can use within a message - these are obviously english, and can be changed in conjuction with the others below in the switch/case statement

Code: [Select]
      string[] commands = {"On", "Toggle", "Off", "Status", "Reset"}; // Commands to look for in message
   


This code specifies what modules to query, you can add to this if required.

Code: [Select]
 
      string moduleTypes = "Light,Dimmer,Switch"; // Types of modules to search


if you want to support other commands or differing languages then edit these case statements accordingly, you can also alter the responses here, the default statement will cause it to send you the status of the module.

Code: [Select]
  switch (command) // command is lowercase
  {
      case "on":
          Program.Notify("Debug", string.Format("Turning Module {0} on.", module.Instance.Name));
          resp = SendMessage(number, string.Format("Turning {0} on.", module.Instance.Name));
          module.On();
          break;
      case "off":
          Program.Notify("Debug", string.Format("Turning Module {0} off.", module.Instance.Name));
          resp = SendMessage(number, string.Format("Turning {0} off.", module.Instance.Name));
          module.Off();
          break;
      case "toggle":
          if (module.Parameter("Status.Level").DecimalValue == 0)
          {
              Program.Notify("Debug", string.Format("Module {0} is currently off, turning on.", module.Instance.Name));
              resp = SendMessage(number, string.Format("{0} is currently off, turning on.", module.Instance.Name));
              module.On();
          }
          else
          {
              Program.Notify("Debug", string.Format("Module {0} is currently on, turning off.", module.Instance.Name));
              resp = SendMessage(number, string.Format("{0} is currently on, turning off.", module.Instance.Name));
              module.Off();
          }
          break;
      case "reset":
          // for alarm
          Program.Notify("Debug", "Not Implemented");
          break;
      default:
          // Program.Notify("Debug", "Unable to determine command, Defaulting to status");
          Program.Notify("Debug", "Module Status Level is " + module.Parameter("Status.Level").DecimalValue);
        resp = SendMessage(number, "Module Status Level is " + module.Parameter("Status.Level").DecimalValue);
          break;
  }


I am playing with NLP (natural language processing) for this but thats a bit of a way of releasing at the moment..

So basically if you send a message saying "step lights on" (assuming you have a module called 'step lights' - it will turn it on.

If you send "step lights" it will tell you the status..

if you send "please would you turn the step lights on"  it will turn them on..

Cheers

David

November 18, 2016, 01:04:47 PM
Reply #12

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34

November 18, 2016, 06:29:34 PM
Reply #13

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
like 1st ur script i have change last line script, then works fine, now my modem go hot  ;D
Many thanks sir.

Now try to edit command processor to do more command  :) ;D :D

November 19, 2016, 02:15:59 PM
Reply #14

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
Can you let me know what you had to change from and to in each script so I can update and then move to github?