HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: [email protected] on November 19, 2015, 03:44:49 PM

Title: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 19, 2015, 03:44:49 PM
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.

Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on December 04, 2015, 01:05:51 AM
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 :)
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on October 14, 2016, 09:23:50 PM
wait for new uodate  ;D
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on October 14, 2016, 09:58:16 PM
Will export my versions later
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on October 14, 2016, 10:04:29 PM
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.
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on October 19, 2016, 10:31:28 AM
Exported these from my system the other day, have changed logging since, will sort out getting these into github

Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 16, 2016, 04:25:05 PM
how to use it can explain?
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 16, 2016, 04:41:35 PM
What hardware do you have for sending the messages and what OS? Or can you post your gammu conf
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 16, 2016, 09:41:59 PM
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
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 17, 2016, 11:54:43 AM
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 :)
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 18, 2016, 11:49:16 AM
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
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 18, 2016, 12:19:02 PM
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
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 18, 2016, 01:04:47 PM
okay will try it
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 18, 2016, 06:29:34 PM
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
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 19, 2016, 02:15:59 PM
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?
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 26, 2016, 11:37:56 PM
I have use ur script and my own modified, ithink problem on my raspi or my os.
i use e173, e488, and vodafone zte, all being not responding after 1 hour.
i check from shell with
$ lsusb
modem detected
but if i check with
$ dmesg | grep tty
usb not shown
then i try to reload with command
$ sudo usb_modeswitch -c /etc/usb_modeswitch.conf
its back work again.

so i have modificate on startup.sh homegenie with thats command
now with your original script, or my own its work perfectly. 1 day i use it, not hang and stay respond all my command. so the problem is mine but i dont know coz the os or my hardware, or my raspi-config.

the problem is every i restart my homegenie or my raspi, GPIO status before restart is ON, after reset it to OFF, i dont know why, try to serach the problem.
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 27, 2016, 04:27:38 PM
Have you inverted the gpio's
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 28, 2016, 03:16:29 PM
No i use standard gpiomodules.hgx

my sms hang this day  :( not respond, restart then normal again  :D
i interest with easyiot its build in smsgateway.
i have load library to my VS2015, its hard 5 years not touch programing, but i will try.

or maybe use this https://www.nuget.org/packages/MessagingToolkit/ (https://www.nuget.org/packages/MessagingToolkit/)

Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 28, 2016, 03:18:30 PM
Got any links to that and where they use it and I can have a look - I may have already dismissed that version for one reason or another if its available via google!
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: djatie on November 28, 2016, 03:48:26 PM
u meand easy iot?
in this link http://iot-playground.com (http://iot-playground.com)

i love homegenie  :-* but easyiot have sms gateway  :-\
my raspi installed on small city with minimum internet acess just got GPRS  ;D so sms is the alternative to control it.
Title: Re: Sending and Receiving SMS (Work in progress)
Post by: [email protected] on November 29, 2016, 03:31:52 PM
if you install ILSpy and then use that you can view what is in there and possibly re-write / add steps into my code if required - just check licensing first :)

I was going to create it as a more robust interface however the issue came around dealing with the serial port and the lack of event handling and then the limitations within the automation programs themselves.

David