Comments (5)
你好,有没有示例程序,如何调用封装库里面的函数,和如何定义ip地址和端口号?谢谢
from blog.
你好,有没有示例程序,如何调用封装库里面的函数,和如何定义ip地址和端口号?谢谢
封装库的函数,其实也就是封装了 AT
指令,你可以参考 SIM800C 通讯的过程,这样子你应该就可以理解了。
至于你说的 IP 和 PORT,我的理解是:服务器的IP地址和端口?
使用这个函数即可,当然你需要保证模块先初始化好。
// 创建 TCP 链接
bool create_tcp(const char *ip, unsigned int port);
该函数等同于 AT+CIPSTART="TCP","IP","POST"
这条 AT 指令。
from blog.
from blog.
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
from blog.
from blog.
Related Issues (20)
- Spring Boot 读取 resources 目录下文件 HOT 2
- 微信公众平台 接口配置 Spring Boot 实现
- docker 容器和镜像导出 / 导入
- mysql 意向锁
- url encode / decode
- Spring 日志切面(Aspect) HOT 1
- Coins
- Json 格式 HOT 1
- 基于 GitHub Action 构建自定义 ElasticSearch Docker 镜像
- docker-compose 水平扩容 HOT 3
- PV / UV
- 域名为什么可以以 . 结尾?
- 关于工具类
- 阿里云 CDN(全站加速)
- Instant.now() 在 jdk1.8 和 jdk11 的区别
- MySQL 比较运算符
- Links
- 为 wget / NPM / Gradle ... 设置代理 HOT 3
- ssh-copy-id 免密码登录服务器
- Github Actions 手动触发 workflow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.