Build and Run

Hello,

I noticed that if I update code and then do a BUILD AND RUN while I’m previewing a Model and a Device, it seems that only that device gets updated and not the rest of the devices.

I thought that when a Build and Run is performed, all devices get updated immediately (the ones that are connect at least)???

‘Build and Run’ applies to the selected device only. If you select a model (rather than a device) this button changes to ‘Build’, which affects all the devices assigned to that model, but doesn’t restart them - they get the new code when they next reboot.

If you’re willing to explore beyond the IDE, the Build API provides a way to achieve what you want, using the restart endpoint.

Hello,
And where fo I use this code as I use perl?

curl -v -X POST -H "Authorization: Basic echo -n [YOUR_API_KEY] | openssl enc -base64" https://build.electricimp.com/v4/devices/devId/restart

And where can I find the API Key, devID and Model ID?

Hello, this is the output that I get… What am I doing wrong?

C:\t1>curl -v -X POST -H -k "Authorization: Basic echo -n [XXXXXXXXXXXXXXXXXXXXXXX] | openssl enc -base64" https://build.electricimp.com/v4/models/Troubleshooting/restart

curl: (3) [globbing] bad range in column 36

  • Trying 54.186.234.31…
  • Connected to build.electricimp.com (54.186.234.31) port 443 (#0)
  • Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
  • TLSv1.2 (OUT), TLS Unknown, Certificate Status (22):
  • TLSv1.2 (OUT), TLS handshake, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Server hello (2):
  • TLSv1.2 (IN), TLS handshake, Certificate (11):
  • TLSv1.2 (OUT), TLS alert, Server hello (2):
  • SSL certificate problem: unable to get local issuer certificate
  • Closing connection 0
    curl: (60) SSL certificate problem: unable to get local issuer certificate
    More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn’t adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you’d like to turn off curl’s verification of the certificate, use
the -k (or --insecure) option.

What is the ModuleID? Is this the name of my model in the IDE (in my case its called Troubleshooting?
Why am I getting all this SSL certificate errors? I even tried with the -k option as it specifies above

Strange, I don’t get that - the same URL above (ok, so a bad api key) gives me this:

$ curl -v -X POST -H -k "Authorization: Basic echo -n [XXXXXXXXXXXXXXXXXXXXXXX] | openssl enc -base64" https://build.electricimp.com/v4/models/Troubleshooting/restart

  • Rebuilt URL to: Authorization: Basic W1hYWFhYWFhYWFhYWFhYWFhYWFhYWFhYXQ==/
  • Could not resolve host: Authorization
  • Closing connection 0
    curl: (6) Could not resolve host: Authorization
  • Trying 54.186.234.31…
  • Connected to build.electricimp.com (54.186.234.31) port 443 (#1)
  • TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
  • Server certificate: *.electricimp.com
  • Server certificate: RapidSSL SHA256 CA - G3
  • Server certificate: GeoTrust Global CA

POST /v4/models/Troubleshooting/restart HTTP/1.1
Host: build.electricimp.com
User-Agent: curl/7.43.0
Accept: /

< HTTP/1.1 401 Unauthorized
< Content-Type: application/json
< Date: Thu, 01 Oct 2015 04:23:25 GMT
< Server: nginx/1.4.2
< X-Node: ide01
< Content-Length: 160
< Connection: keep-alive
<

…what system are you running on, and is it reasonably up to date (SSL root certs, etc)?

Well, the URL’s wrong for a start. You need to add your model’s ID (obtained by first GET-ing a list of models) in place of ‘Troubleshooting’. The model ID is in each model’s entry in that list.

Hello,

Okay I ran the code to get the Models ID as per below, I have replaced my API_KEY below with XXXXXXXXX since this is a public forum. I am indeed using the right API Key that I created within the IDE.

I keep getting error as per below…

I am running curl on windows 7 64bit system and even tried at home on a windows 10 32bit system.

???

C:\t1>curl -k -v -X GET -H "Authorization: Basic echo -n [XXXXXXXXXXXXXXXXXXXXXXXX] | openssl enc -base64" https://build.electricimp.com/v4
/models

  • Trying 54.186.234.31…
  • Connected to build.electricimp.com (54.186.234.31) port 443 (#0)
  • Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
  • TLSv1.2 (OUT), TLS Unknown, Certificate Status (22):
  • TLSv1.2 (OUT), TLS handshake, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Server hello (2):
  • TLSv1.2 (IN), TLS handshake, Certificate (11):
  • TLSv1.2 (IN), TLS handshake, Server key exchange (12):
  • TLSv1.2 (IN), TLS handshake, Server finished (14):
  • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
  • TLSv1.2 (OUT), TLS change cipher, Client hello (1):
  • TLSv1.2 (OUT), TLS handshake, Finished (20):
  • TLSv1.2 (IN), TLS change cipher, Client hello (1):
  • TLSv1.2 (IN), TLS handshake, Finished (20):
  • SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
  • Server certificate:
  •    subject: OU=GT08622464; OU=See www.rapidssl.com/resources/cps (c)14; OU=Domain Control Validated - RapidSSL(R); CN=*.electricimp.com
    
  •    start date: 2014-11-05 08:31:48 GMT
    
  •    expire date: 2016-05-25 02:15:53 GMT
    
  •    issuer: C=US; O=GeoTrust Inc.; CN=RapidSSL SHA256 CA - G3
    
  •    SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
    

GET /v4/models HTTP/1.1
Host: build.electricimp.com
User-Agent: curl/7.44.0
Accept: /
Authorization: Basic echo -n [XXXXXXXXXXXXXXXXXXXXXXXXX] | openssl enc -base64

< HTTP/1.1 401 Unauthorized
< Content-Type: application/json
< Date: Thu, 01 Oct 2015 12:16:28 GMT
< Server: nginx/1.4.2
< X-Node: ide01
< Content-Length: 110
< Connection: keep-alive
<
{“success”:false,“error”:{“code”:“Unauthorized”,“message_short”:“Unauthorized”,“message_full”:“Unauthorized”}}* Connection #0 to host build.electricim
p.com left intact

C:\t1>

Ok, now you’re getting a good TLS handshake but your API key does not appear correct (hence you’re getting an unauthorized response).

The reason why this is happening is that the echo -n ... stuff is something that is executed on a linux or mac box, but on windows will do nothing (unixes execute everything in backticks and insert the output into the command line).

ie, you need to base64 encode your api key on windows. I don’t know how to do that. There are online services that will do this (just google base64 encode) but obviously you’re pasting your key in there which isn’t ideal for security.

The OUTPUT of that should be put into the auth basic string, ie:

curl -k -v - X GET -H “Authorization: Basic YYYYY” https://build.electricimp.com/v4/models

(replacing YYYY with the base64 encoded version of your API key)