# Reference

Soracom Orbit SDK downloads and reference material for module development.

You can find the latest version of the Soracom Orbit SDK in the [Downloads](https://docs.soracom.io/en/services/orbit/download) section.

## AssemblyScript

The `orbit-sdk-assemblyscript` module contains the Orbit AssemblyScript SDK. Import the module into your code in order to use the methods.

```typescript
import {
  log,
  getInputBuffer,
  getInputBufferAsString,
  getTagValue,
  setTagValue,
  deleteTag,
  getSourceValue,
  getLocation,
  getTimestamp,
  getUserdata,
  getOriginalRequest,
  setOutputJSON,
} from "orbit-sdk-assemblyscript";
```

### Function Signatures

| Function | Returns | Description |
| - | - | - |
| **log**(message: _string_) | `void` | Output a string to the log. The logs are retained for up to 7 days. |
| **getInputBuffer**() | _Uint8Array_ | Get the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data) as an array of Uint8. |
| **getInputBufferAsString**() | _string_ | Get the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data) as a character string. |
| **getTagValue**(name: _string_) | _string_ | Get the value of a tag from the data source (SIM). Returns an empty string if the tag name is not found. |
| **setTagValue**(name: _string_, value: _string_) | `void` | Create or update a tag from the data source (SIM). |
| **deleteTag**(name: _string_) | `void` | Delete a tag from the data source (SIM). |
| **getSourceValue**(name: _string_) | _string_ | Get the value of an attribute from the data source (SIM). For `name`, specify one of the properties included in the source of the input to the WASM module (e.g., `resourceType`). Returns an empty string if the attribute is not found. |
| **getLocation**() | Location: { lat: _f64_, lon: _f64_ } | Get the Location object when using a plan-KM1 SIM. Returns `NaN` if the location is not available. |
| **getTimestamp**() | _i64_ | Get the timestamp when Orbit received [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data). |
| **getUserdata**() | _string_ | Get the `userdata` attribute of the Metadata Service. |
| **getOriginalRequest**() | _string_ | Get request data from device. It retrieves the same data as when `getInputBufferAsString()` is called within `uplink()`. |
| **setOutputJSON**(json: _string_) | `void` | Return JSON data to Orbit as the WASM module output data. |

The SDK also includes functions that begin with the `orbit_` prefix, which provide lower level functionality. These functions are wrapped in the methods above, which should be sufficient for most cases, however you can access these functions if you want to output in a format other than JSON:

| Function | Returns | Description |
| - | - | - |
| **orbit\_set\_output**(json: _i32_, len: _i32_) | `void` | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output data. |
| **orbit\_set\_output\_content\_type**(type: _i32_, len: _i32_) | `void` | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output Content-Type. |

Refer to the SDK implementation for how to use the `setOutputJSON()` function.

## Rust

The `orbit-sdk-rust` crate contains the Orbit Rust SDK. Include it in your code in order to use the methods.

```rust
use soracom_orbit_sdk as orbit;
```

### Function Signatures

| Function | Returns | Description |
| - | - | - |
| **log**(message: _\&str_) | | Output a string to the log. The logs are retained for up to 7 days. |
| **get\_input\_buffer**() | _Vec_\<u8> | Get the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data) as a u8a vector. |
| **get\_tag\_value**(name: _\&str_) | _String_ | Get the value of a tag from the data source (SIM). Returns an empty string if the tag name is not found. |
| **set\_tag\_value**(name: _\&str_, value: _\&str_) | | Create or update a tag from the data source (SIM). |
| **delete\_tag**(name: _\&str_) | | Delete a tag from the data source (SIM). |
| **get\_source\_value**(name: _\&str_) | _String_ | Get the value of an attribute from the data source (SIM). For `name`, specify one of the properties included in the source of the input to the WASM module (e.g., `resourceType`). Returns an empty string if the attribute is not found. |
| **get\_location**() | _Option_\<Location>: { lat: _f64_, lon: _f64_ } | Get the Location object when using a plan-KM1 SIM. Returns `None` if the location is not available. |
| **get\_timestamp**() | _i64_ | Get the timestamp when Orbit received [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data). |
| **get\_userdata**() | _String_ | Get the `userdata` attribute of the Metadata Service. |
| **get\_original\_request**() | _String_ | Get request data from device. It retrieves the same data as when `get_input_buffer()` is called within `uplink()`. |
| **set\_output\_json**(json\_str: _\&str_) | | Return JSON data to Orbit as the WASM module output data. |

The SDK also includes functions that begin with the `orbit_` prefix, which provide lower level functionality. These functions are wrapped in the methods above, which should be sufficient for most cases, however you can access these functions if you want to output in a format other than JSON:

| Function | Returns | Description |
| - | - | - |
| **orbit\_set\_output**(ptr: _i32_, len: _i32_) | | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output data. |
| **orbit\_set\_output\_content\_type**(ptr: _i32_, len: _i32_) | | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output Content-Type. |

Refer to the SDK implementation for how to use the `set_output_json()` function.

## C/C++

The `orbit-sdk-c` library contains the Orbit C/C++ SDK. Include it in your code in order to use the methods.

```cpp
#include "soracom/orbit.h"
```

### Function Signatures

| Return Type | Function | Description |
| - | - | - |
| _void_ | **soracom\_log**(const _char\*_ fmt, ...) | Output a string to the log. The logs are retained for up to 7 days. |
| _int32\_t_ | **soracom\_get\_input\_buffer\_as\_string**(const _char\*\*_ buf, _size\_t\*_ siz) | Get the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data) as a buffer. When you have finished using the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data), release the buffer using `soracom_release_input_buffer()` with the \*buf pointer. |
| _void_ | **soracom\_release\_input\_buffer**(const _char\*_ buf) | **deprecated** Frees the memory allocated. Use `soracom_release_buffer` instead |
| _void_ | **soracom\_release\_userdata**(const _char\*_ buf) | **deprecated** Frees the memory allocated. Use `soracom_release_buffer` instead |
| _void_ | **soracom\_release\_buffer**(const _char\*_ buf) | Frees the memory allocated. |
| _int32\_t_ | **soracom\_get\_tag\_value**(const _char\*_ name, _size\_t_ name\_len, const _char\*\*_ value, _size\_t\*_ value\_len) | Get the value of a tag from the data source (SIM). Returns an empty string if the tag name is not found. |
| _void_ | **soracom\_set\_tag\_value**(const _char\*_ name, const _char\*\*_ value) | Create or update a tag from the data source (SIM). |
| _void_ | **soracom\_delete\_tag\_value**(const _char\*_ name) | Delete a tag from the data source (SIM). |
| _int32\_t_ | **soracom\_get\_source\_value**(const _char\*_ name, _size\_t_ name\_len, const _char\*\*_ value, _size\_t\*_ value\_len) | Get the value of an attribute from the data source (SIM). For `name`, specify one of the properties included in the source of the input to the WASM module (e.g., `resourceType`). Returns an empty string if the attribute is not found. |
| _int32\_t_ | **orbit\_has\_location**() | Check if the location information of a plan-KM1 SIM can be obtained. Returns `1` if it can be obtained, and `0` if it cannot. |
| _double_ | **orbit\_get\_location\_lat**() | Get the latitude value of the location information. Returns `undefined` if the location is not available. |
| _double_ | **orbit\_get\_location\_lon**() | Get the longitude value of the location information. Returns `undefined` if the location is not available. |
| _int64\_t_ | **orbit\_get\_timestamp**() | Get the timestamp when Orbit received [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data). |
| _int32\_t_ | **soracom\_get\_userdata\_as\_string**(const _char\*\*_ buf, _size\_t\*_ siz) | Get the `userdata` attribute of the Metadata Service. |
| _int32\_t_ | **soracom\_get\_original\_request\_as\_string**(const _char\*\*_ buf, _size\_t\*_ siz) | Get request data from device. It retrieves the same data as when `soracom_get_input_buffer_as_string()` is called within `uplink()`. |
| _void_ | **soracom\_set\_json\_output**(const _char\*_ buf, _size\_t_ siz) | Return JSON data to Orbit as the WASM module output data. |

The SDK also includes functions that begin with the `orbit_` prefix, which provide lower level functionality. These functions are wrapped in the methods above, which should be sufficient for most cases, however you can access these functions if you want to output in a format other than JSON:

| Return Type | Function | Description |
| - | - | - |
| _void_ | **orbit\_set\_output**(const _char\*_ buf, _size\_t_ siz) | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output data. |
| _void_ | **orbit\_set\_output\_content\_type**(const _char\*_ buf, _size\_t_ siz) | Return the data located in memory indicated by the pointer and length to Orbit as the WASM module output Content-Type. |

Refer to the SDK implementation for how to use the `soracom_set_json_output()` function.

## TinyGo

The Orbit TinyGo SDK is provided at [soracom/orbit-sdk-tinygo](https://github.com/soracom/orbit-sdk-tinygo). Import it in your code in order to use the methods.

```go
import sdk github.com/soracom/orbit-sdk-tinygo
```

### Function Signatures

| Function | Returns | Description |
| - | - | - |
| **Log**(msg _string_) | | Output a string to the log. The logs are retained for up to 7 days. |
| **GetInputBuffer**() | (_\[]byte_, _error_) | Get the [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data) as a buffer. Returns `ErrNoInputBuffer` or `ErrInvalidInputBufferLength` if error occurred. |
| **GetTagValue**(name _string_) | (_\[]byte_, _error_) | Get the value of a tag from the data source (SIM). Returns `ErrNoTagValue` or `ErrInvalidTagValueLength` if error occurred. |
| **SetTagValue**(name _string_, value _string_) | | Create or update a tag from the data source (SIM). |
| **DeleteTag**(name _string_) | | Delete a tag from the data source (SIM). |
| **GetSourceValue**(name _string_) | (_\[]byte_, _error_) | Get the value of an attribute from the data source (SIM). For `name`, specify one of the properties included in the source of the input to the WASM module (e.g., `resourceType`). Returns an empty string if the attribute is not found. Returns `ErrNoSourceValue` or `ErrInvalidSourceValueLength` if error occurred. |
| **GetUserdata**() | (_\[]byte_, _error_) | Get the value of an attribute from the data source (SIM). Returns `ErrNoUserData` or `ErrInvalidLength` if error occurred. |
| **GetOriginalRequest**() | (_\[]byte_, _error_) | Get request data from device. It retrieves the same data as when `GetInputBuffer()` is called within `uplink()`. |
| **GetLocation**() | (_\*Location_, _error_) | Get the Location object when using a plan-KM1 SIM. Location struct should be `{ Lat: _float64_, Lon: _float64_ }`. Returns `ErrNoLocationInformation` if the location is not available. |
| **GetTimestamp**() | _int64_ | Get the timestamp when Orbit received [input data](https://docs.soracom.io/en/services/orbit/reference/#input-data). |
| **SetOutputJSON**(out _string_) | | Return JSON data to Orbit as the WASM module output data. |

## Reference

### Input Data

Input data from Soracom to the WASM module can be retrieved using the Orbit SDK.

Note that the data obtained by calling a "function to retrieve input data for the WASM module" (e.g., `getInputBuffer()` or `getInputBufferAsString()` in AssemblyScript) differs depending on whether it is called from within `uplink()` or `downlink()`.

#### When Called by uplink()

`uplink()` is a function that transforms data sent from the device to Soracom.

When a function to retrieve input data for the WASM module is called within `uplink()`, one of the following types of data may be obtained:

- Data sent from the device to Soracom.
- Data sent from the device to Soracom that has been processed by the Binary Parser.

#### When Called by downlink()

`downlink()` is a function that transforms data being sent from the destination back to the device.

When a function to retrieve input data for the WASM module is called within `downlink()`, it returns the data received from the destination.

> [!NOTE]
>
> The Binary Parser cannot process data being sent from the destination back to the device.

> [!WARNING]
>
> You can also retrieve data that was sent from the device to Soracom within `downlink()`. For example, in AssemblyScript, you can call `getOriginalRequest()`.
