Sending SyncML OTA via PHP

Sending SyncML OTA via PHP SearchSearch
Author Message
Pancho
New member
Username: Pancho

Post Number: 23
Registered: 09-2005
Posted on Tuesday, August 15, 2006 - 06:57 am:   

Hi,

Did anyone experienced in sending SyncML OTA settings via PHP? I know there's an interface that you can simply fill up the form and submit but, I don't want to do it manually.

Please help.

Thanks in advance.

Pancho
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6327
Registered: 10-2002
Posted on Tuesday, August 15, 2006 - 04:51 pm:   

Hi Pancho,

You need to perform an HTTP POST to submit the relevant XML as content.

You could either use PHP functions designed for performing an HTTP POST, or from your script, you just need to open a TCP connection to the port for the NowSMS web interface, and then issue the raw HTTP POST data:

POST /?PhoneNumber=xxxxxxxx&OTA=POST HTTP/1.0
Content-Length: yyyyyy
(*blank line*)
<xml settings document here>

When submitting an OTA request in this manner, the HTTP POST request must include a “Content-Length:” header. This should match the length of your XML document.

NowSMS will scan the XML content to automatically determine what the content type is ... so that it can be encoded properly for sending over the air.

The recipient of is specified in the "PhoneNumber" parameter in the URL of the request.

If you need to use a PIN on the settings, add "&OTAPIN=xxxx" to the URL, along with "&OTAPINTYPE=USERPIN" or "&OTAPINTYPE=NETWPIN".

-bn
Pancho
New member
Username: Pancho

Post Number: 24
Registered: 09-2005
Posted on Thursday, August 17, 2006 - 05:35 am:   

Hi Bryce,

Thank you for the support. However, can you please provide me a complete example of XML settings to be posted? A pattern will be great.

Thanks again.

Pancho
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6372
Registered: 10-2002
Posted on Thursday, August 17, 2006 - 06:10 pm:   

Hi Pancho,

The easiest way to see an example of these XML settings is to use the "View XML" option from the NowSMS web interface when you use the "Send OMA Settings" web form.

Here's a thread with some examples:

http://support.nowsms.com/discus/messages/1/11205.html

But it's probably best to experiment with the "View XML" option in the "Send OMA Settings" page with your own settings.

-bn
Pancho
New member
Username: Pancho

Post Number: 25
Registered: 09-2005
Posted on Friday, August 18, 2006 - 05:18 am:   

Hi Bryce,

I followed your instruction but it's not posting to the gateway. Please see the code below:

<?
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
<wap-provisioningdoc>
<characteristic type="APPLICATION">
<parm name="APPID" value="w5" />
<parm name="TO-NAPID" value="INTERNET" />
<parm name="NAME" value="SyncML" />
<parm name="ADDR" value="http://syncserver:port/path" />
<characteristic type="RESOURCE">
<parm name="URI" value="./contacts" />
<parm name="NAME" value="Contacts DB" />
<parm name="AACCEPT" value="text/x-vcard" />
</characteristic>
<characteristic type="RESOURCE">
<parm name="URI" value="./calendar" />
<parm name="NAME" value="Calendar DB" />
<parm name="AACCEPT" value="text/x-vcalendar" />
</characteristic>
<characteristic type="APPAUTH">
<parm name="AAUTHNAME" value="syncusername" />
<parm name="AAUTHSECRET" value="syncpassword" />
</characteristic>
</characteristic>
</wap-provisioningdoc>';

$path = "http://127.0.0.1:8800/?PhoneNumber=1234567890&OTA=$xml";
$fp = fsockopen("127.0.0.1", 8800, $errno, $errstr) or die("Cant Connect...");

$header = "POST $path HTTP/1.0\r\n";
$header .= "Content-Type: text/xml; charset=ISO-8859-1\r\n";
$header .= "Content-Length: ".strlen($xml)."\r\n\r\n";
$header .= "Connection: Close\r\n\r\n";
fwrite($fp, $header);
fclose($fp);
?>

There's no error in my code above but, it still not posting.

Thank you.

Regards,
Pancho
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6388
Registered: 10-2002
Posted on Friday, August 18, 2006 - 07:06 pm:   

Hi Pancho,

What if you read the HTTP response coming back?

I'd be curious to see the SMSDEBUG.LOG from NowSMS, which should show the raw request that is coming in to NowSMS ... then I could more easily point out what is wrong without trying to figure out your script. (Easiest to enable the SMSDEBUG.LOG from the "Serial #" page of the NowSMS config.)

Actaully, as I look at your script, I think I see a couple of problems ...

You're including the XML in the POST path ... and you definitely do not want to do that. It is the content of the HTTP POST.


Change

$path = "http://127.0.0.1:8800/?PhoneNumber=1234567890&OTA=$xml";

to

$path = "http://127.0.0.1:8800/?PhoneNumber=1234567890&OTA=POST";

Next, insert the following after fwrite($fp, $header);

fwrite ($fp, $xml);


I expect that should work ... but also note the following.

If "Require authentication for web interface" is checked on the "Web" page of the NowSMS configuration dialog, then the above request would be rejected as unauthorised. To get around this, you need to define an account that is allowed to submit to NowSMS on the "SMS Users" dialog. Then append the following to your HTTP POST URL ... "&user=username&password=password"

For clarification, I mean the following:

$path = "http://127.0.0.1:8800/?PhoneNumber=1234567890&OTA=POST&user=username&password=p assword";

Also note that some phones will only accept OTA if it has a USERPIN associated with it. To add a USERPIN of 1111 to the OTA, you would append the following to the URL: "&OTAPIN=1111&OTAPINTYPE=USERPIN"

For the sake of clarification, this becomes:

$path = "http://127.0.0.1:8800/?PhoneNumber=1234567890&OTA=POST&user=username&password=p assword&OTAPIN=1111&OTAPINTYPE=USERPIN";

(Requiring a PIN is a security measure enforced by some handset manufacturers ... they want to avoid end users accidentally accepting configuration settings that the user did not ask for. Therefore, it makes things more secure if the receiving user must know a PIN code for the settings in order to open the settings message. And yes, this does confuse the heck out of mere mortals.)

-bn
Pancho
New member
Username: Pancho

Post Number: 26
Registered: 09-2005
Posted on Saturday, August 19, 2006 - 04:47 am:   

Hi Bryce,

I tested it and it worked! Thank you.

Another thing, can we change the source number to a name when sending? For example, when I send the setting to a person he/she will see a name instead of my mobile number. Can the gateway do this?

Thanks again.

Pancho
Bryce Norwood - NowSMS Support
Board Administrator
Username: Bryce

Post Number: 6396
Registered: 10-2002
Posted on Saturday, August 19, 2006 - 05:12 pm:   

Hi Pancho,

You can set the SMS sender with the &Sender= parameter in the HTTP request, however that will not override the sender if you are sending via a GSM modem, as it is not possible in that environment.

Thsat said, for OTA messages, the SMS sender value is often not the one displayed...see http://support.nowsms.com/discus/messages/485/5910.html for discussion of another parameter that can be set.

-bn