wuji 发表于 2019-4-18 13:36:20

hnyzcj 发表于 2019-4-18 09:52
可能是我表达不够清晰,我想做一下事情:一个主控上挂LED3个(D2,D3,D4),人体D5,温湿度D6,土壤A2,蜂鸣 ...

可以的,在阿里云平台上创建一个产品,为它定义LED1,LED2,LED3,人体温度5等等的功能属性,每个功能都有特定的标识符,再为这个产品创建一个设备,这个设备会继承该产品的所有属性,操作这些标识符就能实现控制和获取信息,关联ESP32和设备,通过上报和订阅和标识符,就能控制ESP32上连接的设备

hnyzcj 发表于 2019-4-18 14:11:04

wuji 发表于 2019-4-18 13:36
可以的,在阿里云平台上创建一个产品,为它定义LED1,LED2,LED3,人体温度5等等的功能属性,每个功能都 ...

有QQ留一个

龙神ldy 发表于 2019-4-22 14:41:13

阿里云发布web以后。指示图标 没有变化,数据已经配置了。开关都正常,就是图标没有反应,按道理 关了是一种颜色,开了是一种颜色。但是怎么就没改变,。

wuji 发表于 2019-4-23 11:02:44

龙神ldy 发表于 2019-4-22 14:41
阿里云发布web以后。指示图标 没有变化,数据已经配置了。开关都正常,就是图标没有反应,按道理 关了是一 ...

关掉物理设备,使用阿里云的在线模拟调试虚拟设备,看看有没有反应

DFByjrZTF9V 发表于 2019-5-1 14:41:14

DFrkjrpHu_E 发表于 2019-3-30 10:16
是的,我也是一样的问题,你有解决吗?

我也一样

DFByjrZTF9V 发表于 2019-5-1 14:43:35

本帖最后由 DFByjrZTF9V 于 2019-5-4 19:21 编辑

为什么我通过手机控制灯的状态,但灯总是一闪一闪的

wuji 发表于 2019-5-16 09:16:56

DFByjrZTF9V 发表于 2019-5-1 14:43
为什么我通过手机控制灯的状态,但灯总是一闪一闪的

检查下程序上报的逻辑

时间都去哪了 发表于 2019-7-3 17:01:32

本帖最后由 时间都去哪了 于 2019-7-3 17:33 编辑

您好楼主,我想问一下,我遇到这种情况应该怎么解决,我是直接复制你的程序代码的。
在用Arduino 1.8.9编译时候提示如下错误:
StaticjsonBuffer是Arduinokson 5中的一个类。请访问arduinokson.org/upgrade了解如何将您的程序升级到arduinokson。
我应该如何解决,谢谢

Z先生 发表于 2019-12-4 20:07:06

你好,请教一下,如果我需要控制两个led,那么回调函数该怎么写呢,一块esp32上有10个数字输出,我在其中两个引脚各连接一个LED。但LED的识别码是不同的,那么Json信息该如何解码呢。

HaVr1rBv 发表于 2019-12-26 17:04:54

您好,我想问一下手机APP一直下载不了,有遇到同样的情况吗?有解决办法吗?

Nicholas 发表于 2020-1-2 05:47:04

楼主很给力

Nicholas 发表于 2020-1-2 06:56:11

努力加油奋斗

Nicholas 发表于 2020-1-2 08:18:44











C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void openLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:30:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, HIGH);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void closeLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:34:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, LOW);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void connectWiFi()':

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:40:37: warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

                                     ^

In file included from C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:1:0:

C:\Users\acer\Desktop\arduino-1.8.3\libraries\WiFi\src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'

   int begin(char* ssid, const char *passphrase);

         ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void callback(char*, byte*, unsigned int)':

sketch_jan02a:74: error: 'client' was not declared in this scope

   client.publish(pubTopic,sendMseg);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void ConnectAliyun()':

sketch_jan02a:78: error: 'client' was not declared in this scope

   while(!client.connected()){

          ^

sketch_jan02a:81: error: 'myAliyun' was not declared in this scope

   if(client.connect(myAliyun.client_id,myAliyun.username,myAliyun.password)){

                     ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void setup()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:94:11: note: in expansion of macro 'BEDROOD_LIGHT'

   pinMode(BEDROOD_LIGHT,OUTPUT);

         ^

sketch_jan02a:100: error: 'myAliyun' was not declared in this scope

   myAliyun.init(ALIYUN_SERVER,ProductKey,ClientId,DeviceName,DeviceSecret);

   ^

sketch_jan02a:102: error: 'client' was not declared in this scope

   client.setServer(myAliyun.mqtt_server,PORT);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void loop()':

sketch_jan02a:118: error: 'client' was not declared in this scope

   if(!client.connected()){

       ^

sketch_jan02a:121: error: 'client' was not declared in this scope

   client.loop();

   ^

exit status 1
'D2' was not declared in this scope

这是什么情况呀

Nicholas 发表于 2020-1-2 08:24:06

非常好









C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void openLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:30:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, HIGH);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void closeLight()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:34:16: note: in expansion of macro 'BEDROOD_LIGHT'

   digitalWrite(BEDROOD_LIGHT, LOW);

                ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void connectWiFi()':

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:40:37: warning: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   WiFi.begin(WIFI_SSID,WIFI_PASSWORD);

                                     ^

In file included from C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:1:0:

C:\Users\acer\Desktop\arduino-1.8.3\libraries\WiFi\src/WiFi.h:79:9: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'

   int begin(char* ssid, const char *passphrase);

         ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void callback(char*, byte*, unsigned int)':

sketch_jan02a:74: error: 'client' was not declared in this scope

   client.publish(pubTopic,sendMseg);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void ConnectAliyun()':

sketch_jan02a:78: error: 'client' was not declared in this scope

   while(!client.connected()){

          ^

sketch_jan02a:81: error: 'myAliyun' was not declared in this scope

   if(client.connect(myAliyun.client_id,myAliyun.username,myAliyun.password)){

                     ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void setup()':

sketch_jan02a:6: error: 'D2' was not declared in this scope

#define BEDROOD_LIGHTD2

                        ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino:94:11: note: in expansion of macro 'BEDROOD_LIGHT'

   pinMode(BEDROOD_LIGHT,OUTPUT);

         ^

sketch_jan02a:100: error: 'myAliyun' was not declared in this scope

   myAliyun.init(ALIYUN_SERVER,ProductKey,ClientId,DeviceName,DeviceSecret);

   ^

sketch_jan02a:102: error: 'client' was not declared in this scope

   client.setServer(myAliyun.mqtt_server,PORT);

   ^

C:\Users\acer\Desktop\sketch_jan02a\sketch_jan02a.ino: In function 'void loop()':

sketch_jan02a:118: error: 'client' was not declared in this scope

   if(!client.connected()){

       ^

sketch_jan02a:121: error: 'client' was not declared in this scope

   client.loop();

   ^

exit status 1
'D2' was not declared in this scope

DFHymJkpq1I 发表于 2020-1-2 09:37:31

exit status 1
'D2' was not declared in this scope

DFS123456 发表于 2020-3-4 12:33:14

连接不成功,rc=2

DFHk-0ykaN8 发表于 2020-3-5 10:24:07

温湿度D6,土壤A2,蜂鸣器D7同时使用的话是否可以实现?引脚够用就可以吗?

DFHk-0ykaN8 发表于 2020-3-17 14:05:51

大神请收下我的膝盖!大神请收下我的膝盖!

HugoWang 发表于 2020-3-29 15:09:58

wuji 发表于 2019-3-14 16:21
阿里云IoT之灯光控制




能否信息我一下,有偿服务,谢谢

kevin_wk 发表于 2023-2-1 15:40:49

这套代码在新版的阿里云Iot(现在的时间是2023-02-01)会有问题了,问题如下:
LED灯会一直被关闭

问题原因:
新版的阿里云Iot,在添加完设备后,会为设备自动定义如下主题,如下图所示:
attach://154277.png
出现问题的地方是,当设备订阅这个主题:/sys/a17x7FncZl0/DPR-LED/thing/event/property/post_reply 后
调用如下方法
/*需要操作的产品标识符*/
String Identifier = "LightStatus";

/*需要上报和订阅的两个TOPIC*/
const char * subTopic = "/sys/a17x7FncZl0/DPR-LED/thing/service/property/set";//****set
const char * pubTopic = "/sys/a17x7FncZl0/DPR-LED/thing/event/property/post";//******post

...

void callback(char * topic, byte * payload, unsigned int len){
Serial.print("Recevice [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < len; i++){
    Serial.print((char)payload);
}
Serial.println();
StaticJsonBuffer<300> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((const char *)payload);
if(!root.success()){
    Serial.println("parseObject() failed");
    return;
}
const uint16_t LightStatus = root["params"];
if(LightStatus == 1){
    openLight();
}else{
    closeLight();
}
String tempMseg = "{\"id\":"+ClientId+",\"params\":{\""+Identifier+"\":"+(String)LightStatus+"},\"method\":\"thing.event.property.post\"}";
char sendMseg;
strcpy(sendMseg,tempMseg.c_str());
client.publish(pubTopic,sendMseg);
}

void setup(){
...
/*开机先关灯*/
closeLight();

/*上报关灯信息*/
client.publish(pubTopic,("{\"id\":"+ClientId+",\"params\":{\""+Identifier+"\":0},\"method\":\"thing.event.property.post\"}").c_str());
}



在函数setup()中调用:client.publish(pubTopic,("{\"id\":"+ClientId+",\"params\":{\""+Identifier+"\":0},\"method\":\"thing.event.property.post\"}").c_str());

阿里云收到消息后,在这个主题“/sys/a17x7FncZl0/DPR-LED/thing/event/property/post_reply” 发送消息,在串口窗口,可以看到返回的参数是:
15:00:16.777 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}

可以看到,返回Json对象,根本没有属性const uint16_t LightStatus = root["params"];
故这里得到 LightStatus 最终为0,根据下面的代码,回关闭LED。
if(LightStatus == 1){
    openLight();
}else{
    closeLight();
;


跟离谱的是,接着下面的代码
}
String tempMseg = "{\"id\":"+ClientId+",\"params\":{\""+Identifier+"\":"+(String)LightStatus+"},\"method\":\"thing.event.property.post\"}";
char sendMseg;
strcpy(sendMseg,tempMseg.c_str());
client.publish(pubTopic,sendMseg)

又会在这个主题
const char * pubTopic = "/sys/a17x7FncZl0/DPR-LED/thing/event/property/post";//******post
上发送消息,又引发回调函数 callback() 响应主题/sys/a17x7FncZl0/DPR-LED/thing/event/property/post_reply
然后造成一些循环,串口将一直输出:
15:00:12.029 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:12.236 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:12.338 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:12.476 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:12.649 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:12.853 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.060 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.161 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.369 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.506 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.677 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.882 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:13.985 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}
15:00:14.090 -> Recevice {"code":200,"data":{},"id":"12345","message":"success","method":"thing.event.property.post","version":"1.0"}

灯将一直被关闭。

在这里,希望官方看看是否更新先示例代码。




成果者也 发表于 2023-3-26 23:25:12

kevin_wk 发表于 2023-2-1 15:40
这套代码在新版的阿里云Iot(现在的时间是2023-02-01)会有问题了,问题如下:
LED灯会一直被关闭



那怎么办啊大佬
页: 1 [2]
查看完整版本: 阿里云IoT灯光控制