public ReturnedState SendATCommand(string atCommand)
{
// Check if module is busy
if (isModuleBusy) return ReturnedState.ModuleBusy;
// Append carriage return
if (atCommand.IndexOf("\r") < 0) atCommand += "\r";
// Check if string is an AT command
if (atCommand.IndexOf("AT") < 0) return ReturnedState.InvalidCommand;
// Check if module is on
if (!isPowerOn) return ReturnedState.ModuleIsOff;
// Check if serial line is open
if (serialLine.IsOpen) serialLine.Write(atCommand);
else return ReturnedState.Error;
Thread.Sleep(100);
DebugPrint("SENT: " + atCommand);
return ReturnedState.OK;
}
will generate an error because it is not an AT command and will not send the data.
To fix this i changed the SendTcpData to
it would be better to split the AT command and the data so the data chunks could be written directly to the module and not the whole data set as this can result im memory errors.
You are correct - the SendTcpData implementation is wrong and will always return InvalidCommand.
If you want to send proper blocks of data, or even receive (the holy grail!) you actually need to put the SIM900 in transparent data mode instead of AT command mode. You need to modify the driver, because as it is written the serial receive thread can only parse AT responses. We set ours up to have a DataMode flag that switches between AT command mode and Modem mode. Note that in Modem mode it is not required to send the (char)26 as data is automatically sent when the serial line is idle for a (configurable) time. If you do send (char)26, it will go in the data stream.
To get out of data mode, you send “+++”. Look at the delays in the sample code. If you don’t use these delays, then the SIM900 will just send the “+++” as data.
@ Byron - thats pretty much what I’m aiming to do, but I’m struggling slightly pulling the code together.
I’ve grabbed your drivers from CodePlex, and the CellularRadioManager extension you posted on the forum. So first off thanks for that.
So I have a test project, which refers to the drivers, and seems pretty happy, can send and recieve txt msgs that kind of thing.
Next I’ve dropped the CellularRadioManager class into the test project, but I can’t figure out where to call it (I’m using the usage code from the forum). I’ve added the ‘usage’ example code to a button pressed event handler, and it successfully retrieves the IMEI, starts up GSM and GPRS, but that’s it.
I’m sorry to be so stupid, but would you be kind enough to provide a bit more context, or a few pointers on how to use the CellularRadioManager?
Initially I’m just trying to hit www.google.com and retrieve data to prove the functionality, then I’ll write a simple webservice.
Would it be a case of making the events in the CellularRadioManager public, and adding handlers in the test project perhaps?
[quote]Your client has issued a malformed or illegal request. Thatâs all we know.
[/quote]
That’s what they tell you. You need to correct that.
To test that, simply use a TELNET app on a PC and telnet to the same address and port 80, and issue the same commands; you should get the same response. When you get the correct response there, put that code into your Fez App.
if (radioManager.IsReady)
{
if (radioManager.Connect(@ "www.google.com")) // add your server address
{
// send data
string crlf = "" + (char)13 + (char)10;
String RequestString = "GET // Http1.1"+crlf;
RequestString += "Host: www.google.com" +crlf + crlf;
if (radioManager.SendData(RequestString))....
but still no joy, still getting the following response from google
CellularRadio : HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 925
Date: Mon, 14 Jan 2013 11:26:14 GMT
Server: GFE/2.0
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 400 (Bad Request)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@ media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>400.</b> <ins>Thatâs an error.</ins>
<p>Your client has issued a malformed or illegal request. <ins>Thatâs all we know.</ins>
I wonder if i’m missing something, maybe, or perhaps it might be better to use the http commands built into the cellular radio sim900 rather than using raw tcp connections?
I tried that, but bizzarely the new command window opened with black text on a black background, so I wasn’t able to see what the responses are doing (I’m running on win2k8 r2). Once I can sort that out i’ll certainly try telnet!