完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,
我想用 esp8266 构建一个恒温器,并通过 Sinricpro 将其连接到 Alexa。我必须说我对 Sinricpro 代码不是很有经验和实践;目前我只从 Github 库“esp8266-esp32-sdk-master”中获取了名为 Thermostat.ino 的示例程序。 我已经输入了 Wi-Fi 和 Sinricpro 连接的所有数据,但目前它连接到互联网(我有串行反馈)但没有连接到 Sinricpro,而且它的网站也处于离线状态。 你有什么建议吗? 谢谢 _ 我附上实用代码 代码:全选 /* * Example for how to use Lock device as garage door opener * * If you encounter any issues: * - check the readme.md at https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md * - ensure all dependent libraries are installed * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#arduinoide * - see https://github.com/sinricpro/esp8266-esp32-sdk/blob/master/README.md#dependencies * - open serial monitor and check whats happening * - check full user documentation at https://sinricpro.github.io/esp8266-esp32-sdk * - visit https://github.com/sinricpro/esp8266-esp32-sdk/issues and check for existing issues or open a new one */ // Uncomment the following line to enable serial debug output //#define ENABLE_DEBUG #ifdef ENABLE_DEBUG #define DEBUG_ESP_PORT Serial #define NODEBUG_WEBSOCKETS #define NDEBUG #endif #include #ifdef ESP8266 #include #endif #ifdef ESP32 #include #endif #include "SinricPro.h" #include "SinricProThermostat.h" #define WIFI_SSID "YOUR_WIFI_SSID" #define WIFI_PASS "YOUR_WIFI_PASSWORD" #define APP_KEY "YOUR_APP_KEY_HERE" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" #define APP_SECRET "YOUR_APP_SECRET_HERE" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" #define THERMOSTAT_ID "YOUR_DEVICE_ID_HERE" // Should look like "5dc1564130xxxxxxxxxxxxxx" #define BAUD_RATE 115200 // Change baudrate to your need float globalTemperature; bool globalPowerState; bool onPowerState(const String &deviceId, bool &state) { Serial.printf("Thermostat %s turned %s\r\n", deviceId.c_str(), state?"on":"off"); globalPowerState = state; return true; // request handled properly } bool onTargetTemperature(const String &deviceId, float &temperature) { Serial.printf("Thermostat %s set temperature to %f\r\n", deviceId.c_str(), temperature); globalTemperature = temperature; return true; } bool onAdjustTargetTemperature(const String & deviceId, float &temperatureDelta) { globalTemperature += temperatureDelta; // calculate absolut temperature Serial.printf("Thermostat %s changed temperature about %f to %f", deviceId.c_str(), temperatureDelta, globalTemperature); temperatureDelta = globalTemperature; // return absolut temperature return true; } bool onThermostatMode(const String &deviceId, String &mode) { Serial.printf("Thermostat %s set to mode %s\r\n", deviceId.c_str(), mode.c_str()); return true; } void setupWiFi() { Serial.printf("\r\n[Wifi]: Connecting"); WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) { Serial.printf("."); delay(250); } IPAddress localIP = WiFi.localIP(); Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]); } void setupSinricPro() { SinricProThermostat &myThermostat = SinricPro[THERMOSTAT_ID]; myThermostat.onPowerState(onPowerState); myThermostat.onTargetTemperature(onTargetTemperature); myThermostat.onAdjustTargetTemperature(onAdjustTargetTemperature); myThermostat.onThermostatMode(onThermostatMode); // setup SinricPro SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); }); SinricPro.begin(APP_KEY, APP_SECRET); } void setup() { Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); setupWiFi(); setupSinricPro(); } void loop() { SinricPro.handle(); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
310 浏览 1 评论
551浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 11:37 , Processed in 0.756193 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号