more G-Labs products

Author Topic: Android Phone as a SMS Gateway by use of a APP  (Read 2244 times)

January 04, 2015, 06:23:24 PM
Read 2244 times

beller

  • *
  • Information
  • Newbie
  • Posts: 24
i try to modify the automation program "Alcatel One Touch Y800Z SMS Notify" of HG to work with the Android App "SMS Gateway Ultimate" (https://play.google.com/store/apps/details?id=com.icecoldapps.smsgatewayultimate&hl=it) installed in a Andorid phone.

I will use it to send my SMS from HG.

I have done the setup of this Andorid app and i have the server running at port 8080 of the phone wifi connection, to send sms from homegenie i use the command (i have removed the previous login web call):

  var request = "smsto=" + smsRecipient + "&smsbody=" + message + "&smstype=sms";
            Net.WebService("http://" + modemAddress + "/send.html?"+request).GetData();

this command is not working, i see that the connection from HG is actived but the app "SMS Gateway Ultimate" say that i have sent wrong parameters, i verify that the parameters are "smsto","smsbody" and "smstype" that is the same inforrmation that i need to enter manually on the SMS page of that app.

I think i have a wrong format or call, i don't know if the call from HG is ok..  i try Post call but i don't works..

any advice ?

this is the source web-page of the service app SMS gateway Ultimate:

---------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Buy SMS Gateway Ultimate Pro</title>
    <style type="text/css">
      body{
        font-family: "Lucida Grande",Calibri,Arial;
        font-size: 9pt;
        color: #333;
        background: #f8f8f8;
      }
      a{
        color: #666666;
        font-size: 11pt;
        font-weight: bold;
        text-decoration: none;
      }
      a:hover{
        color: #000;
      }
      table{
        margin: 0 auto;
        padding: 0;
        width: 600px;
      }
      table td{
        padding: 5px;
      }
      thead td{
        padding-left: 0;
        font-family: "Trebuchet MS";
        font-size: 14pt;
        font-weight: bold;
      }
        tbody td.name{
        width: 99%;
      }
      tbody .file td{
        background: #fff;
        border: solid 1px #ddd;
      }
      tbody tr.file:hover td{
        background: #C4C4C4;
      }
      tbody .file td.size,tbody .file td.time{
        white-space: nowrap;
        padding: 5px 10px;
      }
      tbody .file td.size span{
        color: #999;
        font-size: 8pt;
      }
      tbody .file td.time{
        color: #555;
      }
      tfoot td{
        padding: 5px 0;
        color: #777;
        font-size: 14pt;
        background: #f8f8f8;
        border-color: #f8f8f8;
      }
      tfoot td.ccc{
        text-align: right;white-space: nowrap;
      }
    </style>
  </head>
  <body>
    <table cellpadding="0" cellspacing="1">
      <thead>
        <tr>
          <td colspan="3">
            <form method="GET" action="/send.html">
              <b>To:</b><br />
              <input type="text" name="smsto" id="smsto" style="width:100%"/><br />
              <b>Text:</b><br />
              <textarea name="smsbody" id="smsbody" style="width:100%;height:200px;"></textarea><br />
             
              <b>Type:</b><br />
              <select name="smstype" id="smstype" style="width:100%">
                <option value="sms">SMS</option>
                <option value="email">Email</option>
              </select><br /><br />
             
              <input type="submit" value="Send"/>
            </form>
          </td>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <td class="total">
          </td>
          <td colspan="3" class="ccc">
            <a target="_blank" href="https://play.google.com/store/apps/details?id=com.icecoldapps.smsgatewayultimatepro" style="font-size: 25pt;">Buy SMS Gateway Ultimate Pro</a>
          </td>
        </tr>
      </tfoot>
      <tbody>

      </tbody>
    </table>
  </body>
---------------------------------------------------------------------------

if i run manually i a browser that url:
http://192.168.0.140:8080/send.html?smsto=0001234567&smsbody=testtttt&smstype=sms

it send me a sms correctly (phone number is changed is this example), so i need to reproduce exactly the same from HG.

i found that if i change the last code as:
        else if (module.HasFeature("SMSGateway.NotifyEvents") && (property.Name.StartsWith("Sensor.") || property.Name.StartsWith("Status.")))
        {
            //var message = module.Instance.Name + " " + property.Name + "=" + property.Value + " (" + module.Instance.Domain + "." + module.Instance.Address + ")";
             var message = "testttttttttttttt";
            SmsSend(message);
        }   

so, i overwrite the message with "testttttt" string it send the message correctly, so my problem could be related to how the message is build from the command:

var message = module.Instance.Name + " " + property.Name + "=" + property.Value + " (" + module.Instance.Domain + "." + module.Instance.Address + ")";

this could be a good method to send sms from HG.

thanks for any help/advice
« Last Edit: January 04, 2015, 06:49:24 PM by beller »

January 04, 2015, 07:00:01 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Probably the message needs to be urlencoded:

Code: [Select]
var request = Uri.EscapeUriString("smsto=" + smsRecipient + "&smsbody=" + message + "&smstype=sms");

Cheers,
g.

January 04, 2015, 08:40:32 PM
Reply #2

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
I use the software gammu which permit to interact with mobine network with an USB Key or a phone connected.

more information :
http://www.homegenie.it/forum/index.php?topic=520.msg2934#msg2934
http://wammu.eu/libgammu/

Bye

January 04, 2015, 10:37:35 PM
Reply #3

beller

  • *
  • Information
  • Newbie
  • Posts: 24
i found that the problem is on char "=" in the line:

var message = module.Instance.Name + " " + property.Name + "=" + property.Value + " (" + module.Instance.Domain + "." + module.Instance.Address + ")";

i changed from "=" to " is " and all works good now.

this is the current simple automation program:

Trigger Code:
------------------------------
Program.Setup( () => {
 
    Program.AddInputField("ModemIp", "", "1. Modem IP address");
    Program.AddInputField("ModemUsername", "", "2. Modem username");
    Program.AddInputField("ModemPassword", "", "2. Modem password");
    Program.AddInputField("SmsRecipient", "", "4. Recipient phone number");
 
   Program.AddFeature("Switch,Dimmer,Light,Siren,Sensor,Program,DoorWindow", "SMSGateway.NotifyEvents", "Send SMS on module event");
});
// this program will be running in background
return true;

Program:
------------------------------------------
var modemAddress = Program.InputField("ModemIp").Value;
var modemUsername = Program.InputField("ModemUsername").Value;
var modemPassword = Program.InputField("ModemPassword").Value;
var smsRecipient = Program.InputField("SmsRecipient").Value;

Func<string,bool> SmsSend = new Func<string,bool>((message)=>{
     var success = false;
  /*   var loginData = Net
        .WebService("http://" + modemAddress + "/")
      .Post("username=" + modemUsername + "&password=" + modemPassword)
      .GetData();
   if (loginData.error == "0")
     {   */
  //var request = "smsto=" + smsRecipient + "&smsbody=" + message + "&smstype=sms";
 
        //var request = "smsto=" + smsRecipient + "&smsbody=" + message + "&smstype=sms";        
        //Net.WebService("http://" + modemAddress + "/send.html?" + request); //.GetData();
        //Program.Notify( "SMS Send",request);
 
        Net.WebService("http://"+modemAddress+"/send.html?smsto="+smsRecipient+"&smsbody="+message+"&smstype=sms").GetData();
 

         /*if (smsSend.error == "0")
        {
             success = true;
             Program.Notify("SMS Gateway Ultimate Notify", "SMS succesfully delivered.");
        }
         else
        {
             Program.Notify("SMS Gateway Ultimate Error!", "Could not send SMS (Err:" + smsSend.error + ").");
        }*/
    /*}
     else
    {
       Program.Notify("SMS Gateway Ultimate Error!", "Wrong Modem IP or credentials.");
    }*/
   return success;
});


// We want to do further processing whenever a module changes
When.ModuleParameterChanged( (module, property) => {
     if (Program.InputField("SmsRecipient").Value != "")
    {
        // Security Alarm System Notification
        if (module.Instance.Name == "Security Alarm System" && property.Name == "HomeGenie.SecurityTriggered" && property.Value == "1")
        {
            var source = Program.WithName("Security Alarm System").Parameter("HomeGenie.SecurityTriggerSource").Value;
            SmsSend("WARNING! Alarm was just triggered from " + source);
        }
        else if (module.HasFeature("SMSGateway.NotifyEvents") && (property.Name.StartsWith("Sensor.") || property.Name.StartsWith("Status.")))
        {
            var message = module.Instance.Name + " " + property.Name + " is " + property.Value + " (" + module.Instance.Domain + "." + module.Instance.Address + ")";
       
            SmsSend(message);
        }     
    }
     // returning true, will route event to other listeners
    return true;
 
});

Program.GoBackground();