Module: Particle::Client::Firmware

Included in:
Particle::Client
Defined in:
lib/particle/client/firmware.rb

Overview

Client methods for the Particle firmware flash API

Constant Summary collapse

COMPILE_PATH =
"v1/binaries"
PLATFORMS =
{
  core: 0,
  photon: 6,
  p1: 8,
  electron: 10
}

Instance Method Summary collapse

Instance Method Details

#compile(file_paths, options = {}) ⇒ OpenStruct

Compile firmware from source code for a specific Particle device

Parameters:

  • file_paths (Array<String>)

    File paths to send to cloud and flash

  • options (Hash) (defaults to: {})

    Compilation options :device_id => Compile for a specific device :platform => Compile for a specific platform (:core or :photon) :platform_id => Compile for a specific platform id :product_id => Compile for a specific product

Returns:

  • (OpenStruct)

    Result of flashing. :ok => true on success :errors => String with compile errors



54
55
56
57
58
59
# File 'lib/particle/client/firmware.rb', line 54

def compile(file_paths, options = {})
  normalize_platform_id(options)
  params = file_upload_params(file_paths, options)
  result = post(COMPILE_PATH, params)
  OpenStruct.new(result)
end

#download_binary(binary_id) ⇒ String

Download compiled binary firmware

Parameters:

  • binary_id (String)

    Id of the compiled binary to download

Returns:

  • (String)

    Binary bytes



66
67
68
# File 'lib/particle/client/firmware.rb', line 66

def download_binary(binary_id)
  get(binary_path(binary_id))
end

#flash_device(target, file_paths, options = {}) ⇒ OpenStruct

Flash new firmware to a Particle device from source code or binary

Parameters:

  • target (String, Device)

    A device id, name or Device object that will receive the new firmware

  • file_paths (Array<String>)

    File paths to send to cloud and flash

  • options (Hash) (defaults to: {})

    Flashing options :binary => true to skip the compile stage

Returns:

  • (OpenStruct)

    Result of flashing. :ok => true on success :errors => String with compile errors



32
33
34
35
36
37
38
39
# File 'lib/particle/client/firmware.rb', line 32

def flash_device(target, file_paths, options = {})
  params = file_upload_params(file_paths, options)
  result = put(device(target).path, params)
  if result[:status] == "Update started"
    result[:ok] = true
  end
  OpenStruct.new(result)
end