techiall / Blog

🍋 [My Blog] See discussions
https://github.com/techiall/Blog/discussions
MIT License
8 stars 1 forks source link

SIM800C #3

Open techiall opened 6 years ago

techiall commented 6 years ago

在某宝上买了 SIM800C 开发板(店家记得给我广告费),这样子就不需要自己焊板子了,233

里面店铺还给了相关的资料,动手难度不大。https://pan.baidu.com/s/1b01Wrc

还需要一张卡,买那种 物联卡 就行了,卡放在模块里面前,先要插入手机,激活后才可以使用。注意模块 SIM 插槽的方向,有坑。

USB-TTL 调试

需要 USB-TTL,连线如下

SIM800C - USB-TTL

GND - GND

VCC - 5.0V (3.3V 也是可以的,没什么问题)

R - RXD

T - TXD

SSCOM 软件波特率选择 9600,记得勾选回车换行。

虽然说 SIM800C 自动识别波特率,但是发现选择其他波特率的时候不够稳定。若通过 Arduino Uno 连接,使用 115200 波特率不够稳定,发送 AT 指令后,模块返回数值时会出现乱码,因此才选择使用 9600。

在提供的资料里面,算是很全面了。包括 AT 指令。使用 SIM800C 模块进行 TCP/IP 连接服务器。相关指令。具体参考资料里面的文档 SIM800系列_TCPIP_应用文档_V1.01.pdf

AT+CPIN?
AT+CSQ
AT+CREG?
AT+CGATT?
AT+CSTT="CMNET"
AT+CIICR
AT+CIFSR
AT+CIPSTART="TCP","test.com","8500"
AT+CIPSEND

连接 Arduino Uno

连接方式,参考链接:http://www.ayomaonline.com/programming/quickstart-sim800-sim800l-with-arduino/

代码

#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 8

//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7

//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup() {
  //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  while(!Serial);

  //Being serial communication witj Arduino and SIM800
  serialSIM800.begin(9600);
  delay(1000);

  Serial.println("Setup Complete!");
}

void loop() {
  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){    
    serialSIM800.write(Serial.read());
  }
}

SIM800C AT 指令集成库

在网上找了这个这个硬件的封装库,发现只找到和他类似的,然后就下载来用,后来出了一些问题,看了下实现的源码,发现有些和我使用不符,而且实现起来不是很难,因此自己就写了一个,只写了 HTTP 发送数据。

附上链接 https://github.com/techial1042/SIM800C_Arduino

wanglegang commented 4 years ago

你好,有没有示例程序,如何调用封装库里面的函数,和如何定义ip地址和端口号?谢谢

techiall commented 4 years ago

你好,有没有示例程序,如何调用封装库里面的函数,和如何定义ip地址和端口号?谢谢

封装库的函数,其实也就是封装了 AT 指令,你可以参考 SIM800C 通讯的过程,这样子你应该就可以理解了。

至于你说的 IP 和 PORT,我的理解是:服务器的IP地址和端口?

使用这个函数即可,当然你需要保证模块先初始化好。

// 创建 TCP 链接
bool create_tcp(const char *ip, unsigned int port);

该函数等同于 AT+CIPSTART="TCP","IP","POST" 这条 AT 指令。

wanglegang commented 4 years ago

techial您好,很高兴收到您的回信: 我想: 1:在程序里调用您的封装库里面的函数,以调用at指令. 2:在程序里面定义ip地址和端口号.

------------------ 原始邮件 ------------------ 发件人: "techial"<notifications@github.com>; 发送时间: 2020年2月29日(星期六) 中午12:41 收件人: "techial1042/Blog"<Blog@noreply.github.com>; 抄送: "乐刚"<124051517@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [techial1042/Blog] SIM800C (#3)

你好,有没有示例程序,如何调用封装库里面的函数,和如何定义ip地址和端口号?谢谢

封装库的函数,其实也就是封装了 AT 指令,你可以参考 SIM800C 通讯的过程,这样子你应该就可以理解了。

至于你说的 IP 和 PORT,我的理解是:服务器的IP地址和端口?

使用这个函数即可,当然你需要保证模块先初始化好。 // 创建 TCP 链接 bool create_tcp(const char *ip, unsigned int port);
该函数等同于 AT+CIPSTART="TCP","IP","POST" 这条 AT 指令。

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

techiall commented 4 years ago

techial您好,很高兴收到您的回信: 我想: 1:在程序里调用您的封装库里面的函数,以调用at指令. 2:在程序里面定义ip地址和端口号.

include

include "SIM800C.h"

//SIM800 TX is connected to Arduino D8

define SIM800_TX_PIN 8

//SIM800 RX is connected to Arduino D7

define SIM800_RX_PIN 7

//Create software serial object to communicate with SIM800 SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

const char *ip[ ] = "192.168.1.100"; unsigned int port =8000;

void setup() { //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor) Serial.begin(9600); while(!Serial);

//Being serial communication witj Arduino and SIM800 serialSIM800.begin(9600); delay(1000);

Serial.println("Setup Complete!"); serialSIM800.println("Setup Complete serialSIM800!"); SIM800C.init(); delay(1000); SIM800C.restart(); delay(1000); }

void loop() { //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor if(serialSIM800.available()){ Serial.write(serialSIM800.read()); } //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800 if(Serial.available()){ serialSIM800.write(Serial.read()); } }

先引入头文件

#include "SIM800C.h"

接着定义一个实例,和一些常量。

SIM800C sim(7, 8, 9600); // TX, RX
const char *ip = "ip"; // ip address
const unsigned int port = 8080; // port

SIM800C 初始化

    sim.restart();
    delay(2000);
    sim.multi_link_mode(false);
    delay(2000);
    sim.init();
    delay(1000);
    sim.apn();
    delay(1000);
    Serial.println("init--------");

    // 我也提供了发送 AT 指令的函数接口,如下
    //  sim.send_at_command("AT+IPR=9600");

SIM800C TCP 链接和发送

    char buf[350] = {0};
    sim.create_tcp(ip, port); // 创建 TCP
    sim.tcp_send(buf); // 发送数据
    sim.close_tcp_link() // 关闭 TCP
wanglegang commented 4 years ago

多谢,疑问已解决!

------------------ 原始邮件 ------------------ 发件人: "techial"<notifications@github.com>; 发送时间: 2020年3月1日(星期天) 下午2:29 收件人: "techial1042/Blog"<Blog@noreply.github.com>; 抄送: "乐刚"<124051517@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [techial1042/Blog] SIM800C (#3)

techial您好,很高兴收到您的回信: 我想: 1:在程序里调用您的封装库里面的函数,以调用at指令. 2:在程序里面定义ip地址和端口号.

include <SoftwareSerial.h>

include "SIM800C.h"

//SIM800 TX is connected to Arduino D8

define SIM800_TX_PIN 8

//SIM800 RX is connected to Arduino D7

define SIM800_RX_PIN 7

//Create software serial object to communicate with SIM800 SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

const char *ip[ ] = "192.168.1.100"; unsigned int port =8000;

void setup() { //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor) Serial.begin(9600); while(!Serial);

//Being serial communication witj Arduino and SIM800 serialSIM800.begin(9600); delay(1000);

Serial.println("Setup Complete!"); serialSIM800.println("Setup Complete serialSIM800!"); SIM800C.init(); delay(1000); SIM800C.restart(); delay(1000); }

void loop() { //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor if(serialSIM800.available()){ Serial.write(serialSIM800.read()); } //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800 if(Serial.available()){ serialSIM800.write(Serial.read()); } }

先引入头文件

include "SIM800C.h"

接着定义一个实例,和一些常量。 SIM800C sim(7, 8, 9600); // TX, RX const char *ip = "ip"; // ip address const unsigned int port = 8080; // port

SIM800C 初始化 sim.restart(); delay(2000); sim.multi_link_mode(false); delay(2000); sim.init(); delay(1000); sim.apn(); delay(1000); Serial.println("init--------"); // 我也提供了发送 AT 指令的函数接口,如下 // sim.send_at_command("AT+IPR=9600");

SIM800C TCP 链接和发送 char buf[350] = {0}; sim.create_tcp(ip, port); // 创建 TCP sim.tcp_send(buf); // 发送数据 sim.close_tcp_link() // 关闭 TCP

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.