0

I'm new to cumulocity application development. Now I'm learning to use Smart App Toolkit to develop HTML5 application.
I could create device in my Tenant, and could run some operations with servces provided in the SDK. However, I failed to create operation with c8yDeviceControl.create(). I got 400 (bad request) error code after the operation, and if I look deeper with chrome develop tool, it shows

{error: "Failed to parse JSON string"},

Here is my code, which I pick up from the Smart SDK sample code, with modifition to reference my deviceId:

var operation = {
                  deviceId: 12111,
                  com_cumulocity_model_WebCamDevice: {
                      name: 'take picture',
                      parameters: {
                          duration: '5s',
                          quality: 'HD'
                      }
                  }
              };
              c8yDeviceControl.create(operation);

Could anyone provide me a help to fix this problem?
Thanks.

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
D. Chen
  • 11
  • 1

1 Answers1

2

The deviceID needs to be a string. This works:

var operation = {
                  deviceId: '1211',
                  com_cumulocity_model_WebCamDevice: {
                      name: 'take picture',
                      parameters: {
                          duration: '5s',
                          quality: 'HD'
                      }
                  }
              };
              c8yDeviceControl.create(operation);

Sorry for the inconvenience, we'll update the documentation.

Stilltorik
  • 1,662
  • 4
  • 19
  • 31
  • Thanks for your quick respone. it works, I could create an operation in the cumulocity server, but in the meantime, there are some error messages release my chrome browser. Right now, I setup the app from localhost, and run the app from chrome browser on same PC. Here are the logs from chrome browser: – D. Chen Oct 24 '16 at 09:54
  • angular.js:9997 TypeError: Cannot read property 'match' of null at k (deviceControl.js:267) at wrappedCallback (angular.js:11498) at wrappedCallback (angular.js:11498) at angular.js:11584 at Scope.$eval (angular.js:12608) at Scope.$digest (angular.js:12420) at Scope.$apply (angular.js:12712) at done (angular.js:8315) at completeRequest (angular.js:8527) at XMLHttpRequest.xhr.onreadystatechange (angular.js:8466) – D. Chen Oct 24 '16 at 09:54
  • Could you write a new question with your issue? It makes it easier to respond to, especially if others want to dive in. Also, please the response of the operation. – Stilltorik Oct 24 '16 at 10:11
  • OK, I just wirte a new question about the issue. – D. Chen Oct 24 '16 at 12:05