mqtt

【华为云技术分享】基于小熊派STM32芯片的通过MQTT上报JSON数据到华为物联网平台的自动售货机Demo解析

匆匆过客 提交于 2020-01-22 21:06:33
【摘要】 STM32的工程在文章末尾,可自行下载。 一、工程配置 1、MCU类型选择STM32L431RC 2、烧录器选择OpenOCD,参数 -f interface/stlink-v2-1.cfg -f target/stm32l4x.cfg 3、输出目录选择 LiteOS_Lab_STM32\targets\STM32L431_BearPi\GCC\appbuild 4、编译器Makefile选择 targets\STM32L431_BearPi\GCC\Makefile 5、平台参数配置:LiteOS_Lab_STM32\demos\oc_mqtt_demo\oc_mqtt_demo_static\oc_mqtt_static.c 6、WIFI用户名密码配置: LiteOS_Lab_STM32\iot_link\network\tcpip\esp8266_socket\esp8266_socket_imp.h 7、在物联网平台上创建产品,选择MQTT方式 二、部分代码解析 编译烧录程序之前我们需要修改两处代码 第一处打开oc_mqtt_static.c文件,我们需要配置设备连接华为云,物联网平台所需要的参数, 修改第51行CN_MQTT_EP_NOTE_ID 为在华为云,设备接入服务,注册设备时使用的设备识别码,可以在平台中查看, 修改CN_MQTT_EP_DEVICE

How to use the un-blocking method of MqttClient

拟墨画扇 提交于 2020-01-22 03:35:13
问题 When I try the below code to connect to the mosquitto broker, as you know, connecting to the broker might takes few seconds/minutes, and during that time when the button pressed to connect, it remains pressed till the connection established and when the connection established the button released back to its normal state. As far as I know, there are two way for connecting a client using paho java API , the blocking method and unblocking method . my question is, how to use the unblocking method

How does the MQTT works? unable to get the data if the receiver file is started after the sender file

∥☆過路亽.° 提交于 2020-01-21 19:13:14
问题 I'm new in MQTT there is a simple range of numbers which I want to print I have created 2 files in which the 1st file whose send data to the 2nd file and the script is like that: sender.py import paho.mqtt.client as mqtt client = mqtt.Client() client.connect("192.168.1.169", 1883, 60) for i in range(1,100): client.publish("TestTopic", i) print(i) client.disconnect() receiver.py: import paho.mqtt.client as mqtt def on_connect(client, userdata, flags, rc): print("Connected with result code "

一条物联网设备控制命令的一生

一笑奈何 提交于 2020-01-21 18:11:12
-----概述------ 为能有效地对设备进行管理,设备的产品模型中定义了物联网平台可向设备下发的命令,应用服务器可以调用物联网平台开放的API接口向单个设备或批量设备下发命令,或者用户通过物联网平台直接向单个设备下发命令,以实现对设备的远程控制。 华为物联网平台有两种命令下发机制: 立即下发:不管设备是否在线,平台收到命令后立即下发给设备。如果设备不在线或者设备没收到指令则下发失败。支持给本应用的设备和被授予权限的其它应用的设备下发命令。 立即下发适合对命令实时性有要求的场景,比如路灯开关灯,燃气表开关阀。使用立即下发时,命令下发的时机需要由应用服务器来保证。 缓存下发:物联网平台在收到命令后先缓存,等设备上线或者设备上报数据时再下发给设备,如果单个设备存在多条缓存命令,则进行排队串行下发。支持给本应用的设备和被授予权限的其它应用的设备下发命令。 缓存下发适合对命令实时性要求不高的场景,比如配置水表的参数。 对于使用LWM2M/CoAP协议的设备,建议用户使用缓存下发模式,工作模式设置为PSM模式(系统默认值)。如需使用立即下发模式(工作模式设置为DRX或eDRX模式),需要在设备上报数据后立即下发命令才能成功。 对于集成了Agent Lite SDK或使用原生MQTT协议的设备,物联网平台仅支持立即下发模式。 -----业务流程----- LWM2M/CoAP协议设备场景

How to add proxy settings in Paho-MQTT?

送分小仙女□ 提交于 2020-01-21 12:09:00
问题 #!/usr/bin/env python # -*- coding: utf-8 -*- # Client paho-mqtt MqttServer # main.py import paho.mqtt.publish as publish from json import dumps from ssl import PROTOCOL_TLSv1 import urllib2 class MqttClient(): host = 'mqtt.xyz.com' port = '1883' auth = {} topic = '%s/streams' tls = None def __init__(self, auth, tls=None): self.auth = auth self.topic = '%s/streams' % auth['username'] if tls: self.tls = tls self.port = '8883' def publish(self, msg): try: publish.single (topic=self.topic

How to add proxy settings in Paho-MQTT?

ⅰ亾dé卋堺 提交于 2020-01-21 12:08:09
问题 #!/usr/bin/env python # -*- coding: utf-8 -*- # Client paho-mqtt MqttServer # main.py import paho.mqtt.publish as publish from json import dumps from ssl import PROTOCOL_TLSv1 import urllib2 class MqttClient(): host = 'mqtt.xyz.com' port = '1883' auth = {} topic = '%s/streams' tls = None def __init__(self, auth, tls=None): self.auth = auth self.topic = '%s/streams' % auth['username'] if tls: self.tls = tls self.port = '8883' def publish(self, msg): try: publish.single (topic=self.topic

【整理】消息队列-ActiveMQ(一)

99封情书 提交于 2020-01-20 16:24:53
ActiveMQ简介 ActiveMQ是一种开源的基于JMS(Java Message Servie)规范的一种消息中间件的实现,ActiveMQ的设计目标是提供标准的,面向消息的,能够跨越多语言和多系统的应用集成消息通信中间件。 数据传送流程 PS:消息协商器(Message Broker),在一个连接中,客户端声明了一个通道,通过单一连接到协商器的并发控制需要建立一个可靠的模型,这里可以使用通道池和串行访问或者例如线程本地通道这样的线程并发模型。 通俗来讲就是指该MQ的服务端。 两种消息传递类型 1)点对点传输,即一个生产者对应一个消费者,生产者向broke推送数据,数据存储在broke的一个队列中,当消费者接受该条队列里的数据。 2)基于发布/订阅模式的传输,即根据订阅话题来接收相应数据,一个生产者可向多个消费者推送数据,与MQTT协议的实现是类似的。 两种消息传递类型的不同,点对点传输消费者可以接收到在连接之前生产者所推送的数据,而基于发布/订阅模式的传输方式消费者只能接收到连接之后生产者推送的数据。 MQTT协议 MQTT的全称是“ Message Queuing Telemetry Transport”,即消息队列遥测传输,是一种基于 订阅/发布模式 的应用层协议,而http是一种基于 restful风格 的一种应用层协议。 MQTT协议是一种轻量级协议,作为一种低开销

Saving MQTT data from subscribe topic on a text file

谁说我不能喝 提交于 2020-01-17 16:32:25
问题 I am setting up to receive MQTT data from a subscribed topic and I want to save the data in a text file. I have added the code to save the variable to a text file. However this doesn't work as it gives me just the variable and not the value of it i.e. doesn't give me the values of "on_message". Can someone please help me? Thanks My code is as follows: import paho.mqtt.client as mqttClient import time def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected to broker") global

error when publish data to aws IoT using BG96 and MQTT protocol

落爺英雄遲暮 提交于 2020-01-16 18:14:25
问题 I'm trying to publish my data to Amazon web services using BG96 (NB-IoT device that use AT commands) I'm following the official documentation (Quectel) so I configure SSL parameters ( with the command : at+ qsslcfg=...) and start MQTT SSL connection successfully (AT+QMTOPEN=...) but when I try to connect to MQTT server( AT+QMTCONN=...), the connection is closed immediately Please help,how can I fix this problem and publish my data to Amazon web services ? AT+QSSLCFG="ciphersuite",1,0x0035 OK

error when publish data to aws IoT using BG96 and MQTT protocol

坚强是说给别人听的谎言 提交于 2020-01-16 18:14:10
问题 I'm trying to publish my data to Amazon web services using BG96 (NB-IoT device that use AT commands) I'm following the official documentation (Quectel) so I configure SSL parameters ( with the command : at+ qsslcfg=...) and start MQTT SSL connection successfully (AT+QMTOPEN=...) but when I try to connect to MQTT server( AT+QMTCONN=...), the connection is closed immediately Please help,how can I fix this problem and publish my data to Amazon web services ? AT+QSSLCFG="ciphersuite",1,0x0035 OK