All Projects → AngelLiang → Esp8266_aliyun_mqtt_app

AngelLiang / Esp8266_aliyun_mqtt_app

Licence: mit
基于ESP8266官方SDK快速接入阿里云物联网平台

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Esp8266 aliyun mqtt app

Blinker Doc
blinker中文文档
Stars: ✭ 139 (+71.6%)
Mutual labels:  mqtt, iot, esp8266, wifi
Awtrix1.0
(Outdated) Smart RGB Matrix Clock
Stars: ✭ 99 (+22.22%)
Mutual labels:  mqtt, iot, esp8266, wifi
Blinker Library
An IoT Solution,Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.
Stars: ✭ 1,095 (+1251.85%)
Mutual labels:  mqtt, iot, esp8266, wifi
Espmqttclient
Wifi and MQTT handling for ESP8266 and ESP32
Stars: ✭ 169 (+108.64%)
Mutual labels:  mqtt, iot, esp8266, wifi
swifitch-software
Software for SWIFITCH HW
Stars: ✭ 12 (-85.19%)
Mutual labels:  mqtt, esp8266, wifi
Bleeper
Library to manage your firmware configurations written in C++
Stars: ✭ 54 (-33.33%)
Mutual labels:  iot, esp8266, wifi
Tuya Convert
A collection of scripts to flash Tuya IoT devices to alternative firmwares
Stars: ✭ 3,338 (+4020.99%)
Mutual labels:  mqtt, iot, esp8266
Esphelper
A library to make using WiFi & MQTT on the ESP8266 easy.
Stars: ✭ 310 (+282.72%)
Mutual labels:  mqtt, esp8266, wifi
Esp8266 React
A framework for ESP8266 & ESP32 microcontrollers with a React UI
Stars: ✭ 193 (+138.27%)
Mutual labels:  mqtt, iot, esp8266
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+3980.25%)
Mutual labels:  iot, esp8266, wifi
Esp Mqtt Json Multisensor
(OBSOLETE) ESP MQTT JSON Multisensor for Home Assistant. Supported sensors include the TEMT6000 light, AM312 PIR, DHT22 temperature/humidity sensors. RGB led supports flash, fade, and transition. Over-The-Air (OTA) uploading, too!
Stars: ✭ 323 (+298.77%)
Mutual labels:  mqtt, esp8266, wifi
Tasmota
Alternative firmware for ESP8266 with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
Stars: ✭ 16,624 (+20423.46%)
Mutual labels:  mqtt, iot, esp8266
Pjon
PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.
Stars: ✭ 2,615 (+3128.4%)
Mutual labels:  mqtt, iot, esp8266
Cicada-FW
IoT Communications Module for Energy Access. An easy way to get production ready, bi-directional communications for your IoT embedded device. Proiect supported by the EnAccess Foundation - https://enaccess.org
Stars: ✭ 12 (-85.19%)
Mutual labels:  mqtt, esp8266, wifi
Wthermostatbeca
Replaces original Tuya firmware on Beca thermostat with ESP8266 wifi module
Stars: ✭ 204 (+151.85%)
Mutual labels:  mqtt, iot, esp8266
Esphome
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Stars: ✭ 4,324 (+5238.27%)
Mutual labels:  mqtt, iot, esp8266
Sonoff Homeassistant
Firmware for ESP8266 based itead Sonoff switches for use with HomeAssistant
Stars: ✭ 354 (+337.04%)
Mutual labels:  mqtt, iot, esp8266
Mqtt via esp01
TCP/UDP Applicaton for UNO/MEGA/STM32 using ESP8266's AT firmware.
Stars: ✭ 23 (-71.6%)
Mutual labels:  mqtt, esp8266, wifi
Esp mqtt
MQTT client library for ESP8266
Stars: ✭ 1,047 (+1192.59%)
Mutual labels:  mqtt, iot, esp8266
Blynk Server
Blynk is an Internet of Things Platform aimed to simplify building mobile and web applications for the Internet of Things. Easily connect 400+ hardware models like Arduino, ESP8266, ESP32, Raspberry Pi and similar MCUs and drag-n-drop IOT mobile apps for iOS and Android in 5 minutes
Stars: ✭ 8 (-90.12%)
Mutual labels:  mqtt, iot, esp8266

esp8266_aliyun_mqtt_app

基于ESP8266官方SDK接入阿里云物联网平台,只需填入阿里云设备认证三元组即可快速接入。

相关博客:使用ESP8266(基于官方SDK)接入阿里云物联网平台

本人所用的环境

使用步骤

  1. 首先到乐鑫官网github下载ESP8266_NONOS_SDK;

  2. 下载本仓库,然后拷贝aliyun_mqtt_app文件夹到SDK主目录,用法类似于ESP8266_NONOS_SDK/examples里面的工程;

  3. 在ESP8266 IDE里导入整个SDK,如果不熟悉该环境,参考这里

  4. 使用SDKv3.0.0还需要修改该SDK的顶层Makefile。编辑器打开该SDK的顶层Makefile,找到下面配置变量,修改SPI_SIZE_MAP为4(如果是使用32Mbit Flash)。

    # ...
    # 25行
    BOOT?=none
    APP?=0
    SPI_SPEED?=40
    SPI_MODE?=QIO
    SPI_SIZE_MAP?=4
    

    如果不修改,后面编译会报下面错误:

    #error "The flash map is not supported"
    
  5. 最后编译下载即可(建议先clean)。

project_list

如果想试试用smartconfig配置Wi-Fi信息,可下载smartconfig分支。

配置信息

当在阿里云物联网平台获取到设备认证三元组后,编辑app/include/user_config.h文件,修改下面信息,然后编译下载并重启ESP8266,最后应该就能在控制台看到设备上线了。

注意,阿里云三元组的宏定义,从上到下分别是:产品key,设备name,设备secret。不要拷贝错了。

#define PRODUCT_KEY     "PRODUCT_KEY"

#define DEVICE_NAME     "DEVICE_NAME"
#define DEVICE_SECRET   "DEVICE_SECRET"

#define WIFI_SSID       "WIFI_SSID"
#define WIFI_PASS       "WIFI_PASS"

当ESP8266IDE的Console打印出以下信息,则表示编译成功:

...
!!!
No boot needed.
Generate eagle.flash.bin and eagle.irom0text.bin successully in folder bin.
eagle.flash.bin-------->0x00000
eagle.irom0text.bin---->0x10000
!!!

编译成功

烧写bin

这一步对新手来说可能坑比较多。可参考安信可的烧写步骤,也可参考我ESP8266-Demos仓库里wiki的烧写说明(目前待完善)。

对老手来说,平时怎么烧写就怎么烧写。

主要模块说明

  • mqtt/:mqtt主模块,从官方SDK中的example/esp_mqtt_proj项目移植过来的;
  • user/md5.c:md5加密模块,生成阿里云mqtt password需要用到hmacmd5
  • user/aliyun_mqtt.c:生成阿里云mqtt信息的核心模块,主要包括mqtt hostmqtt portmqtt client idmqtt username以及动态生成的mqtt password
  • user/user_smartconfig.c:smartconfig模块(smartconfig分支才有),当定义了SMARTCONFIG_ENABLE可以以手机配网的方式给ESP8266连接Wi-Fi。

注意事项

  • 关于串口波特率

    ESP8266串口打印默认为74880bps,如果串口工具没有74880bps也可以选择76800bps。

    或者修改下user/user_main.c/user_init()的代码:

    // ...
    void user_init(void) {
        //uart_init(BIT_RATE_74880, BIT_RATE_74880);
        uart_init(BIT_RATE_115200, BIT_RATE_115200);
        //...
    }
    
  • 关于源码文件中的中文乱码

    因为源码文件编码默认为UTF-8,而Windows Eclipse IDE默认为GBK,所以可能需要设置一下:

    菜单栏Window -> Preferences -> General -> Workspace -> 面板Text file encoding -> 选择UTF-8 -> OK

串口打印效果图

MQTT连接阿里云成功:

MQTT连接成功

接收云端下发的命令hello world

接收云端下发的命令

排错

首先要调试好ESP8266串口能正常打印出信息。一般来说,使用74880bps不会有乱码,使用115200bps,开头一小段会有乱码。

wifi连接失败

如果wifi连接失败,会重复打印下面信息:

下面是表示找不到WIFI_SSID的wifi热点。

no WIFI_SSID found, reconnect after 1s
reconnect
wifi connect fail!
wifi connect fail!
wifi connect fail!
wifi connect fail!
wifi connect fail!
wifi connect fail!
scandone
no WIFI_SSID found, reconnect after 1s
reconnect
wifi connect fail!
wifi connect fail!
wifi connect fail!
wifi connect fail!
wifi connect fail!
scandone
no WIFI_SSID found, reconnect after 1s
wifi connect fail!
reconnect
wifi connect fail!
wifi connect fail!
wifi connect fail!

wifi密码错误及其他原因则不断打印「wifi connect fail!」信息,因为本人没有在代码层面上做更多的判断。

MQTT连接阿里云失败

打印信息:

connected with TP-LINK, channel 13
dhcp client start...
wifi connect fail!
ip:192.168.0.113,mask:255.255.255.0,gw:192.168.0.1
TCP: Connect to domain PRODUCT_KEY.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883
DNS: found ip ******
TCP: connecting...
MQTT: Connected to broker PRODUCT_KEY.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to PRODUCT_KEY.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883
MQTT: Connected
MQTT: queue subscribe, topic"/PRODUCT_KEY/DEVICE_NAME/get", id: 1
MQTT: queuing publish, length: 41, queue size(37/2048)
TCP: Disconnected callback
MQTT: Disconnected

可以看到末尾有TCP/MQTT断开了连接的信息:

...
TCP: Disconnected callback
MQTT: Disconnected

其他补充

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].