首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用amazon mqtt从esp8266发布按钮按键

使用amazon mqtt从esp8266发布按钮按键
EN

Stack Overflow用户
提问于 2020-11-08 05:48:39
回答 1查看 114关注 0票数 0

在mongoose os中,我有以下代码打印到我的串行控制台。我可以在amazon aws中看到该设备,在mdash中将其显示为在线。我从pub返回了一个0,但它从未向aws mqtt发送消息。我已经在mqtt的测试部分订阅了该主题,所以不确定我做错了什么

代码语言:javascript
复制
load("api_gpio.js");
load("api_mqtt.js");
load("api_sys.js");
let pin = 0;
GPIO.set_button_handler(
  pin,
  GPIO.PULL_UP,
  GPIO.INT_EDGE_NEG,
  50,
  function (x) {
    let topic = "mOS/topic1";
    let message = JSON.stringify({
      total_ram: Sys.total_ram(),
      free_ram: Sys.free_ram(),
    });
    let ok = MQTT.pub(topic, message, message.length);
    let test = ok;
    let res = MQTT.pub("mOS/topic1", JSON.stringify({ a: 1, b: 2 }), 1);

    print(res);
    print("Published:", res ? "yes" : "no");
  },
  true
);
print("Flash button is configured on GPIO pin", pin);
print("Press the flash button now!");

MQTT.sub(
  "mOS/topic1",
  function (conn, topic, msg) {
    print("Topic:", topic, "message:", msg);
  },
  null
);

我很确定我已经满足了所有这些要求

有效的连接

有效且有效的证书

允许所需连接和操作的策略

我有一个包含以下内容的mos-default策略

代码语言:javascript
复制
{
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:*",
      "Resource": "*"
    }
  ],
  "Version": "2012-10-17"
}

下面是一个mos.yml文件。而且我的应用程序里确实有aws.crt.pem和aws.key.pem文件。

代码语言:javascript
复制
author: mongoose-os
description: A JS-enabled demo Mongoose OS firmware
# arch: PLATFORM
version: 1.0
manifest_version: 2017-05-18
libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

config_schema:
  - ["mqtt.server", "iot.eclipse.org:1883"]
  - ["i2c.enable", true]

tags:
  - js

filesystem:
  - fs

libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/js-demo-bundle

conds:
  # It's not that we can't work with multicore
  # but we cannot afford it because of space (32K).
  - when: mos.platform == "esp32"
    apply:
      build_vars:
        ESP_IDF_SDKCONFIG_OPTS: >
          ${build_vars.ESP_IDF_SDKCONFIG_OPTS}
          CONFIG_FREERTOS_UNICORE=y
代码语言:javascript
复制
let connected = MQTT.isConnected();

print(connected);

返回false,我不确定如何调试此

我遵循了这里的所有说明,包括互联网按钮视频https://mongoose-os.com/docs/mongoose-os/cloud/aws.md

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-10 04:59:07

好了,它又开始工作了,我需要在amazon中删除该设备,然后再次运行mos aws setup命令。

所以真正的问题是,我每次更新代码时都会刷新我的设备,它会覆盖我的wifi设置、aws设置和mdash设置。

多亏了另一个source的帮助,这为我解决了这个问题

代码语言:javascript
复制
Use mos call FS.List to get a directory listing of the files in your device
Use mos get to retrieve your credentials and save them locally in your fs dir.
E.g.:

$ mos get aws-esp32_807A98.key.pem > fs/aws-esp32_807A98.key.pem
$ mos get aws-esp32_807A98.crt.pem > fs/aws-esp32_807A98.crt.pem
$ mos get ca.pem > fs/ca.pem
Use mos config-get to read your config, or just copy from that verbose output you get when you initialize your device. Save those to mos.yml.
E.g.:

["aws.thing_name", ""]
["mqtt.enable", true]
["mqtt.server", "a1234b5678cde-ats.iot.us-east-2.amazonaws.com:8883"]
["mqtt.ssl_ca_cert", "ca.pem"]
["mqtt.ssl_cert", "aws-esp32_807A98.crt.pem"]
["mqtt.ssl_key", "aws-esp32_807A98.key.pem"]
So, when you re-flash, you re-write your credentials and configure your device with the same data again.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64732769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档