Home > other >  Node. Js' excuse me TypeError: device. Serve is not a function "the reason for the error
Node. Js' excuse me TypeError: device. Serve is not a function "the reason for the error

Time:10-11

//load the SDK
Const aliyunIot=the require (' aliyun - iot device - SDK);
//create a device instance
Const device=aliyunIot. Device ({
//activate the credentials, replace here in platform application to a real device credentials
ProductKey: 'a1lDtBtQ1eR',
DeviceName: 'test2',
Wnnv5kpkbzzj3q3wplnh1k36s0gry9f deviceSecret: '2',
});
Device. On (' connect ', ()=& gt; {
//the connection is successful
The console. The log (' connect successfully ');
//to monitor the cloud message
Device. Serve (' property/set, params=& gt; {
The console. The log (' receieve params: ', params);
//the same report
The console. The log (' post props: 'params);
Device. PostProps (params, err=& gt; {
If (err) {
Return the console. The log (' post error: 'err);
}
The console. The log (' post successfully! ');
});
});
});
Device. On (' error '(err)=& gt; {
The console. The log (' error 'err);
});



Error: PS C: \ Users \ moreo \ virtual - nodejs> Node index. Js
Connect successfully
C: \ Users \ moreo \ virtual - nodejs \ index js: 14
Device. Serve (' property/set, params=& gt; {
^
TypeError: device. Serve is not a function
Ats Device. & lt; anonymous> (C: \ Users \ moreo \ virtual - nodejs \ index js: 14:12)
Ats Device. Emit (events. Js: 209:13)
The at MqttClient. & lt; anonymous> (C: \ Users \ moreo \ virtual - nodejs/node_modules/aliyun - iot - device - SDK \ lib \ device js: 379:18)
The at MqttClient. Emit (events. Js: 214:15)
At MqttClient. _handleConnack (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 918:10)
At MqttClient. _handlePacket (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 350:12)
5 (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 292:12)
The at Writable. Writable. _write (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 302:5)
The at doWrite (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ readable - stream \ lib \ _stream_writable js: 428:64)
The at writeOrBuffer (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ readable - stream \ lib \ _stream_writable js: 417:5)
PS C: \ Users \ moreo \ virtual - nodejs> Node index. Js
Connect successfully
C: \ Users \ moreo \ virtual - nodejs \ index js: 14
Device. Serve (' property/set, params=& gt; {
^
TypeError: device. Serve is not a function
Ats Device. & lt; anonymous> (C: \ Users \ moreo \ virtual - nodejs \ index js: 14:12)
Ats Device. Emit (events. Js: 209:13)
The at MqttClient. & lt; anonymous> (C: \ Users \ moreo \ virtual - nodejs/node_modules/aliyun - iot - device - SDK \ lib \ device js: 379:18)
The at MqttClient. Emit (events. Js: 214:15)
At MqttClient. _handleConnack (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 918:10)
At MqttClient. _handlePacket (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 350:12)
5 (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 292:12)
The at Writable. Writable. _write (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ MQTT \ lib \ client js: 302:5)
The at doWrite (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ readable - stream \ lib \ _stream_writable js: 428:64)
At writeOrBuffer (C: \ Users \ moreo \ virtual - nodejs \ node_modules \ readable - stream \ lib \ _stream_writable js: 417:5)

CodePudding user response:

Go to the website https://github.com/aliyun/alibabacloud-iot-device-sdk: equipment serve method into onService.
  • Related