Chinaunix首页 | 论坛 | 博客
  • 博客访问: 66335
  • 博文数量: 19
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-13 16:29
文章分类

全部博文(19)

文章存档

2010年(9)

2009年(10)

我的朋友

分类: LINUX

2009-09-21 23:00:54

现在我有simcom公司的sim300一块,并配有开通gprs业务中国移动sim卡一张。嵌入式系统是s3c2410,基本的sms业务已经实现了。接下来想通过gprs建立和服务器的通信,所使用的协议是sim300内置的tcp、ip协议栈。
 
因为UDP比较简单,故采用之。
我的过程如下:
 
记录一:
Client====please input gprs test AT Cmd or "exit":   #系统提示
at+cipcsgp=1,"cmnet"
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+clport="udp","8888"    #设定传输模式和端口号
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cstt
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+ciicr
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cifsr
                                                                               
10.192.37.195
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cipstart="udp","219.245.106.114","4567"  #设置服务器参数,即将开始传送数据了
                                                                               
CONNECT OK
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cifsr
                                                                               
10.192.37.195
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cipstatus
                                                                               
OK
                                                                               
STATE: CONNECT OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cipsend
No data
                                                                               
>
Input data to send to server!(end with "Enter")
23455
No data           
#发送失败,在服务器端监听的套接字没有接受到数据
###########################################################
 
记录二:
Client====please input gprs test AT Cmd or "exit":    #系统提示
at+cipcsgp=1,"cmnet"
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+clport="udp","8888"
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cstt
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+ciicr
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cifsr
                                                                               
10.196.101.96
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cipstart="udp","219.245.106.114","4567"    #告诉服务器,即将开始发送数据
                                                                               
CONNECT OK
                                                                               
OK
                                                                               
Client====please input gprs test AT Cmd or "exit":
at+cipsend
return with No Data
Input data to send to server!(end with "Enter")
abcdef
return with No Data
Client====please input gprs test AT Cmd or "exit":
at
return with No Data
########################################################
at+cipsend后,始终没有出现期待的send ok
 
两次尝试均告失败,估计是客户端程序中,数据发送格式有问题,明天期待进一步完善。
~~~
 
今天终于把程序调通了,可以发送UDP数据到公网服务器。
 
服务器我是用的公网真实ip。
实验室因为是局域网,不方便。而寝室有固定的公网ip,就想了个办法。
使用vnc远程控制软件登陆到宿舍,控制宿舍电脑,建立服务器。这样一来有了公网ip,可以任意设置监听端口,
二来可以查看接收状况,三来还可以调试程序,做一切在宿舍电脑可以做的事情。
 
好了,现在我的发送、接收模式就清楚了:
       UDP
sim300-----》server
 
下面就是我的操作过程:
======================================
 
input:  at
return:  at
  OK
input:  ate0  #关闭回显
return:  ate0
  OK
input:  at+ccid  #查看sim卡工作否
return:  XXXXXXXXXX
  OK
input:  at+cipcsgp=1,"cmnet" #选择gprs方式上网,默认接入点cmnet
return:  OK
input:  at+cipstatus  #查询SIM300 TCP/IP连接的工作状态
return:  OK
  STATE: IP INITAL
input:  at+clport="udp","9000" #设置SIM300本地的端口模式
return:  OK
input:  at+cstt   #开始工作
return:  OK
input:  at+ciicr   #激活gprs连接
return:  OK
input:  at+cifsr  #查看梦网分配的内网ip:10.192.38.199
return:  10.192.38.199
input:  at+cipstart="udp","219.245.16.114","3456" #连接远端服务器
return:  CONNECT OK
  OK
input:  at+cipstatus  #查询状态
return:  OK
  CONNECT OK
input:  at+cipsend  #以命令模式(command)发送数据
return:  No data   #程序自定义的提示返回,非SIM300返回数据
  >
Please input data to send to server(end with "Enter"):
data from sim300 gprs model.
length of datas:XX
data from sim300 gprs model.
return:  SEND OK
接下来就可以在远端的服务器上接收到数据:“data from sim300 gprs model.”
 
==============================================================
 
回忆前几天问题之所在,现在得以解决,速度还算可以,称得上是解决问题的方法吧,这里拿出来和大家
分享分享。
最初我们把问题定位在两方面:一是连接模型选择有问题。我们试过两块sim300的点对点模式,以及现在这种
客户服务器模式,都没有成功。
二是代码编写有问题。当时没太在意这方面。
 
后来在网上查询了大量资料以后,我确信是我们的编码有问题,而不是模式选择,模块和中国移动已经把一切
都封装好的,不应该涉及太难的东西。
所以就是编程有问题,最后还是发现了在at+cipsend处出现问题了,一个指针用完后没有置零,结果导致每次
发送数据都没有0x1a(ctrl+z)的发送标志。难怪每次都发送等待了,看来一切都明朗了。
 
改完以后,一试就成啦。。。
                                                                   ~~~~~~~~~~~~~~~~完
阅读(3262) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~