TCP server command read
hi!
i use tcp server gsm.. works great how read command client?
i use php script:
and use sim900 gsm modem gsm gpr sgps ide100 v307 library
so send command php , in arduino tcp server serial monitor
but how command?
sorry english
arduino code:
i use tcp server gsm.. works great how read command client?
i use php script:
code: [select]
<?php
// check if form was submitted
if($_post['send']){
// open client connection to tcp server
if(!$fp=fsockopen('90.134.66.170',80,$errstr,$errno,30)){
trigger_error('error opening socket',e_user_error);
}
$message=$_post['message'];
// write message to socket server
fputs($fp,$message);
// get server response
//$ret=fgets($fp,1024);
// close socket connection
fclose($fp);
echo '<h1>you entered the following message in
lowercase :'.$ret.'</h1>';
exit();
}
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html>
<head>
<title>testing tcp socket server</title>
<meta http-equiv="content-type" content="text/html; charset=iso-
8859-1" />
</head>
<body>
<h1>enter message here</h1>
<form action="<?php echo $_server['php_self']?>" method="post">
<input type="text" name="message" size="30" /><br />
<input type="submit" name="send" value="send value" />
</form>
</body>
</html>
and use sim900 gsm modem gsm gpr sgps ide100 v307 library
so send command php , in arduino tcp server serial monitor
but how command?
sorry english
arduino code:
code: [select]
#include "sim900.h"
#include <softwareserial.h>
#include "inetgsm.h"
inetgsm inet;
char msg[50];
int numdata;
char inserial[50];
int i=0;
boolean started=false;
long lasttime=millis();
void setup()
{
serial.begin(9600);
serial.println("gsm shield testing.");
if(gsm.begin(2400)){
serial.println("\nstatus=ready");
}else{
serial.println("\nstatus=idle");
}
if (inet.attachgprs(" ", " ", " ")){
serial.println("status=attached");
}else{
serial.println("status=error");
}
gsm.simplewriteln("at+cifsr");
delay(5000);
gsm.whilesimpleread();
senddata();
//read ip address.
gsm.simplewriteln("at+cifsr");
delay(5000);
int i=0;
while(i<20){
gsm.simpleread();
i++;
}
//tcp server. start socket connection
//as server on assigned port.
serial.println(msg);
delay(5000);
if (inet.connecttcpserver(80))
serial.println("status=tcpserverwait");
else serial.println("error in server");
lasttime=millis();
}
void senddata(){
numdata=inet.httppost("www.klondaikas.lt", 80, "/ip.php", "testas=asd", msg, 50);
serial.println("\nnumber of data received:");
serial.println(numdata);
serial.println("\ndata received:");
serial.println(msg);
}
void loop(){
if(started){
//check if there active connection.
if (inet.connectedclient()){
//read , print last message received.
gsm.read(msg, 50);
serial.println(msg);
}
}
else{
serialhwread();
serialswread();
}
};
void serialhwread(){
i=0;
if (serial.available() > 0){
while (serial.available() > 0) {
inserial[i]=(serial.read());
delay(10);
i++;
}
inserial[i]='\0';
if(!strcmp(inserial,"/end")){
serial.println("_");
inserial[0]=0x1a;
inserial[1]='\0';
gsm.simplewriteln(inserial);
}
//send saved @ command using serial port.
if(!strcmp(inserial,"test")){
serial.println("signal quality");
gsm.simplewriteln("at+csq");
}
//read last message saved.
if(!strcmp(inserial,"msg")){
serial.println(msg);
}
else{
serial.println(inserial);
gsm.simplewriteln(inserial);
}
inserial[0]='\0';
}
}
void serialswread(){
gsm.simpleread();
}
someone?
Arduino Forum > Using Arduino > Programming Questions > TCP server command read
arduino
Comments
Post a Comment