How to implement embedded Mqtt Client using W5500 IC

STM32 开发板引脚:
STM32F10x引脚接口
MACEEP_SCL_Pin—->PB6—->替换成PB10
MACEEP_SDA_Pin—->PB7—->替换成PB11
USART RX —->PA10
USART TX —->PA9
LED1_Pin —->PE0—->替换成PB5
LED2_Pin —->PE1—->替换成PE5
W5500_RESET_PIN —->PD10
W5500_INT_PIN —->PD11
W5500_CS_PIN —->PA4
W5500_CLK_PIN —->PA5
W5500_MISO_PIN —->PA6
W5500_MOSI_PIN —->PA7

Step 1: Stuffs that you have to prepare.
1. W5500 Embedded Ethernet Board.
- W5500 with Cortex M Series recommended. I used my custom board. My custom ethernet board includes W5500 and stm32f103vc(ST’s cortex M3).
2. IDE.
- Whatever you want. I used CoIDE(with gcc).
3. Broker Server.
- A. Use Cloud Services, such as CloudMQTT. - Recommended.
- B. Make you own broker server using cloud server service, such as google cloud or aws.

Step 2: Preparing Broker server - CloudMQTT
1. Visit the http://www.cloudmqtt.com/
2. Sign up with your e-mail and login.
3. Create CloudMQTT Instance.
4. Complete.

Step 3: Paho mqtt library download and import.
1. Visit the https://eclipse.org/paho/
2. Download C/C++ MQTT Embedded clients and unzip.
3. Import MQTT library(You have to import 1 Folder & 2 Files)
A. Folder: c:\your downdload path\org.eclipse.paho.mqtt.embedded-c-1.0.0\MQTTPacket\src
B. Files: c:\your downdload path\org.eclipse.paho.mqtt.embedded-c-1.0.0\MQTTClient-C\src MQTTClient.c & .h files.

Step 4: MQTT Library porting.
1. Create new file. MQTTInterface.c & MQTTInterface.h (File name is not important.)
2. Define the functions and structures.
3. coding Main() using MQTT library.
You can download full source code from my github:https://github.com/bangbh81/paho-mqtt-subscribe-example

Step 5: Test
这里写图片描述
设置MQTT代理服务器地址和端口号
1. MQTT FX(mqtt pc client software from http://mqttfx.jfx4ee.org/
2. make a connection propile using CloudMQTT Instance info.
A. Broker Server Address
B. Broker Port
C. User Name
D. Password
3. Connect and Write a topic & data.
4. Click publish.
5. Check the mqtt client works well.

编写一个使用SMTP协议的电子邮件客户端程序,我们可以选择Java作为语言,因为它有丰富的库支持网络编程。下面是一个简单的步骤来创建这样的程序: 1. **环境设置**: - 首先,你需要安装Java Development Kit (JDK) 和一个邮件发送库,如JavaMail API 或 Apache Commons Email。 2. **项目结构**: - 创建一个新的Java项目,包含`EmailClient` 类负责处理SMTP交互。 3. **导入必要的库**: ```java import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; ``` 4. **配置邮箱信息**: ```java String host = "smtp.example.com"; int port = 587; // 对于SMTP通常使用TLS端口 String username = "your_email@example.com"; String password = "your_password"; ``` 5. **连接到SMTP服务器**: ```java Properties properties = new Properties(); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(properties, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); Transport transport = session.getTransport("smtp"); transport.connect(host, port, username, password); ``` 6. **构建并发送邮件**: ```java MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); message.setTo(new InternetAddress("recipient@example.com")); message.setSubject("Test Email"); String body = "Hello, this is a test email sent using SMTP."; message.setText(body); transport.sendMessage(message, message.getAllRecipients()); ``` 7. **关闭连接**: ```java transport.close(); ``` 8. **运行和测试**: - 编译并运行程序,检查是否能成功发送一封邮件。 ```cpp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值