Git Product home page Git Product logo

Comments (5)

wanglegang avatar wanglegang commented on July 30, 2024

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

from blog.

techiall avatar techiall commented on July 30, 2024

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

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

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

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

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

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

from blog.

wanglegang avatar wanglegang commented on July 30, 2024

from blog.

techiall avatar techiall commented on July 30, 2024

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.

wanglegang avatar wanglegang commented on July 30, 2024

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.