Skip to content

Commit

Permalink
extended publish
Browse files Browse the repository at this point in the history
  • Loading branch information
rickkas7 committed Jan 28, 2025
1 parent d973698 commit 467f48f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 57 deletions.
36 changes: 18 additions & 18 deletions config/sitemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -1279,8 +1279,8 @@
"hash": "cb17b9b3cc4a6b1ec669a68399d39a931f48c10d502ec671a80efe0ae79624f6"
},
"reference/device-os/firmware.md": {
"date": "2025-01-27",
"hash": "d3e04a0ec8eb80d9ea368d4d77c1efb29f40ca5f60709578a41588fede171dc0"
"date": "2025-01-28",
"hash": "02acdd658030634f5529ba19d3bc3251377f47f1c1de4d063c1b329d55877672"
},
"reference/device-os/pin-info.md": {
"date": "2022-05-18",
Expand Down Expand Up @@ -8223,8 +8223,8 @@
"date": "2023-11-08"
},
"getting-started/new.md": {
"hash": "43dc5ec9577785f3e3ca7f960eaa37fbc03c906600d4a1e68d25c30e34d4c1ec",
"date": "2025-01-27"
"hash": "74f971de0ad522ac296887a5030571b37d3b83d7abd3af74e52169b7c2f6491b",
"date": "2025-01-28"
},
"getting-started/cloud/logic.md": {
"hash": "71a1026986a744d0446ae3a1156cbcb68840de48db731768ccedc6861c035c16",
Expand Down Expand Up @@ -9447,8 +9447,8 @@
"date": "2025-01-15"
},
"reference/device-os/typed-publish.md": {
"hash": "26bd7c0e4b088bae11a9275b9d178cb4b8aefba76b94e1e0c0c8c79722ea8b7a",
"date": "2025-01-27"
"hash": "f9ffe1a33a26020e7422d7ecde06a40ee44bc459ae404fdff79b600521cb75fb",
"date": "2025-01-28"
},
"troubleshooting/led.md": {
"hash": "df60457eef43105be5df19b65e3f0e556ba9ccad05ad6bb979405f056d124ef7",
Expand Down Expand Up @@ -9635,32 +9635,32 @@
"date": "2025-01-27"
},
"reference/device-os/api/cloudevent/getting-and-settings-cloudevent.md": {
"hash": "1c6915428333004bcc0b24c7009c2921eb5ab90cf9da4d7dc26f55870c1eb167",
"date": "2025-01-27"
"hash": "7e3d61b2ed6a0ffae0539692274428b440fddda5859a7e5a77a3b33f7bfe0101",
"date": "2025-01-28"
},
"reference/device-os/api/cloudevent/file-read-and-write-cloudevent.md": {
"hash": "ffea583e8bcbf56f4174c13dffeb075486938587e61c9862206da9d084055473",
"date": "2025-01-27"
"hash": "541d1ad21e8ff53ef8101c06989b3d682979f2c1ada8d9e5f7d4a6609f0ab82a",
"date": "2025-01-28"
},
"reference/device-os/api/cloudevent/utility-methods-cloudevent.md": {
"hash": "a08c3ce29845b85aa470fc11fbb4f05dad5170715bf36f0e4ad6df57536317f4",
"date": "2025-01-27"
"hash": "ba7e4216dd1bf310e29f5dc3fc1d80275863ed193a12c9fe90af6da35b5094ad",
"date": "2025-01-28"
},
"reference/device-os/api/cloudevent/stream-methods-cloudevent.md": {
"hash": "ca4cc1056e74ca15dfaf1a66ec32143f486e884f8c2055be60a184a8062f7b50",
"date": "2025-01-27"
"hash": "7fdeea711131393310a5c69933117481fba174a40e508ff07fbc2d2bd5752646",
"date": "2025-01-28"
},
"reference/device-os/api/cloudevent/publish-status-cloudevent.md": {
"hash": "a8ca3c8f85b098ccc7b36843b0df50026bb05e386264d33263435208655cd0e4",
"date": "2025-01-27"
"hash": "55a1fda7de55f1918f128dd4562e46532284a6b49bc80f008b2153cf9d5948be",
"date": "2025-01-28"
},
"reference/device-os/api/subscribe/subscribe-cloudevent-subscribe.md": {
"hash": "d53b638fbe6a3fdf1e6b1dcc070174e739f6fb0b29cf1ca90db86b2eef7fd029",
"date": "2025-01-27"
},
"reference/device-os/api/subscribe/subscribeoptions-subscribe.md": {
"hash": "35974c8b4ebb7c89f995a38848857e28d0c565eb31d5552b819daf0ba77325ed",
"date": "2025-01-27"
"hash": "33d73f975b531988e8ab7714bae9df011cf98446ab3394c1823a2d21d48b29b7",
"date": "2025-01-28"
},
"reference/device-os/api/eventdata/eventdata.md": {
"hash": "5d341114d1aa0cc1336253204c2c1901a256aed88561fa57f382d656a96095a4",
Expand Down
25 changes: 6 additions & 19 deletions src/assets/files/extended-publish/BinaryData.cpp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/content/getting-started/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ When adding new items to this page:
The header format must be exactly that because the search feature uses that to delimit entries, and determine the date of entries
--}}

### Extended publish API 2025-01-28

Documentation for features in Device OS 6.3.0 include: [Typed and extended publish](/reference/device-os/typed-publish/) (includes examples),
[CloudEvent](/reference/device-os/api/cloudevent/) (the most important class for this feature), and
[Particle.publish](/reference/device-os/api/publish/particle-publish-cloudevent-publish/).

### Updated logic APIs 2025-01-27

Documentation for the [Logic geocoding API](/getting-started/logic-ledger/logic/#particle-geocoding-api) and [getDeviceLocation](/getting-started/logic-ledger/logic/#getdevicelocationoptions-core-api) is now available.
Expand Down
49 changes: 36 additions & 13 deletions src/content/reference/device-os/firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -1519,12 +1519,14 @@ When publishing you typically set the value, but you can also get the value that

When subscribing to an event, you typically get the value to see what the publisher or the event has set.

You don't typically sent the content type to `STRUCTURED`; when you set the data from a `Variant` this is handled automatically for you.

#### data - from c-string - CloudEvent

Copies data from a c-string (null terminated string) into the event data.

Typically used with the TEXT content type. The data cannot contain a null byte at a location other than the
end of a string so this is not suitable for many types of binary data.
Typically used with the `TEXT` content type. The data cannot contain a null byte at a location other than the
end of a string so this is not suitable for binary data.

```cpp
// PROTOTYPE
Expand All @@ -1548,6 +1550,8 @@ CloudEvent& data(const char* data, size_t size);

Copies data from a buffer specified with pointer and length. This is typically used with binary data.

See [Content-Type](#contenttype-cloudevent), above, for the valid values.

```cpp
// PROTOTYPE
CloudEvent& data(const char* data, size_t size, ContentType type)
Expand All @@ -1562,7 +1566,6 @@ Copies data from a `String` object.
CloudEvent& data(const String& data)
```


#### dataString - CloudEvent

Returns a copy of the data in the `EventData` object as a `String`. This is typically used for text data.
Expand All @@ -1574,7 +1577,7 @@ String dataString() const

#### data from Buffer - CloudEvent

Copies binary data from a `Buffer object.
Copies binary data from a `Buffer` object. This is an alternative to using a pointer and length.

```cpp
// PROTOTYPE
Expand Down Expand Up @@ -1608,6 +1611,8 @@ Returns a copy of the structured data in the `CloudEvent` as an `EventData` obje
EventData dataStructured() const
```

For more information, see [structured subscription](/reference/device-os/typed-publish/#structured-subscription) in the typed and extended publish page.

### File read and write - CloudEvent

Event data can be saved to a file and restored from a file easily. For more information about the file system, see [File system](/reference/device-os/file-system/) and [File system API](#file-system).
Expand All @@ -1634,29 +1639,33 @@ Returns 0 on success or a non-zero system error code.
int saveData(const char* path)
```

Error::FILE, "File error", -225


### Utility methods - CloudEvent

#### setSize - CloudEvent

Set the size of the data. This is rarely needed.

```cpp
// PROTOTYPE
int setSize(size_t size)
```

#### size - CloudEvent

Get the size of the data. This is the encoded size so there is computation involved in getting this value.

You may want to use this with [canPublish](#canpublish-cloudevent) to see if the event can be published
based on the current rate limiting.

```cpp
// PROTOTYPE
size_t size() const
```



#### isEmpty - CloudEvent

Returns true if the event is empty (no has data).

```cpp
// PROTOTYPE
bool isEmpty() const
Expand All @@ -1669,21 +1678,26 @@ read or write the event data as a stream of bytes.

#### seek - CloudEvent

Seek to a position relative to the start of the data (0 = first byte).

```cpp
// PROTOTYPE
int seek(size_t pos)
```


#### pos - CloudEvent

Returns the current position in the data.

```cpp
// PROTOTYPE
size_t pos() const
```

#### write - CloudEvent

Write a byte or bytes to the data at the current position.

```cpp
// PROTOTYPES
size_t write(uint8_t b) override
Expand All @@ -1694,6 +1708,8 @@ int write(const char* data, size_t size)

#### read - CloudEvent

Read a byte or bytes from the data at the current position.

```cpp
// PROTOTYPES
int read() override
Expand All @@ -1702,13 +1718,18 @@ int read(char* data, size_t size)

#### readBytes - CloudEvent

Read a bytes from the data at the current position.

```cpp
// PROTOTYPE
size_t readBytes(char* data, size_t size) override
```

#### peek - CloudEvent

Read a byte or bytes from the data at the current position but do not move the current
position so the next read will read the same bytes.

```cpp
// PROTOTYPES
int peek() override
Expand Down Expand Up @@ -1799,13 +1820,13 @@ bool isValid() const


#### error - CloudEvent


Returns a 0 if the event is not in a failed or invalid state, otherwise a system error code defined `Error::Type`, which is a negative value.

```cpp
// PROTOTYPE
int error() const;
```

Returns a 0 if the event is not in a failed or invalid state, otherwise a system error code defined `Error::Type`, which is a negative value.

See [system errors](#system-errors) for the available error codes.

Expand Down Expand Up @@ -1975,6 +1996,8 @@ SubscribeOptions& structured(bool enabled)
bool structured() const;
```

For more information, see [structured subscription](/reference/device-os/typed-publish/#structured-subscription) in the typed and extended publish page.

### Subscribe (with Variant) - Subscribe

{{since when="6.2.0"}}
Expand Down
15 changes: 9 additions & 6 deletions src/content/reference/device-os/typed-publish.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Typed publish
title: Typed and extended publish
layout: commonTwo.hbs
columns: two
description: Typed publish for Particle IoT devices
Expand All @@ -16,7 +16,7 @@ In Device OS 6.3.0 and later, extended publish builds upon typed publish and pro

### Large events - Extended publish

In Device OS 6.3.0 and later, events can be up to 16,384 in size. Previously, event payloads were limited to 1024 bytes or less.
In Device OS 6.3.0 and later, events can be up to 16,384 bytes in size and can contain binary data. Previously, event payloads were limited to 1024 bytes or less.

Large events count as 1 data operation for each 1024 bytes of data, rounded up. A publish of 1000 bytes count as a 1 data operation, but 1300 bytes counts as 2 data operations. A maximum event size of 16 Kbytes counts as 16 data operations.

Expand Down Expand Up @@ -62,14 +62,14 @@ size, however, and the size after Base 64 encoding can exceed 1024 bytes.

Say you have this binary data that you publish from a device:

```
```html
0000: a7 22 98 1c 40 1b 9b 80 bb 9d d9 c0 13 bb 4e d0 | " @ N
0010: a3 c0 ae 81 c5 93 91 2a 83 8e 69 27 b0 c6 17 26 | * i' &
0020: 85 93 b7 a6 f5 69 c0 4c 9e 3d 53 49 b5 47 f0 44 | i L =SI G D
0030: 26 9b 8a 1d e4 bc 73 f9 4d a4 e8 34 c2 56 17 c9 | & s M 4 V
```

A webhook using \{{{PARTICLE_EVENT_VALUE}} will receive this payload:
A webhook using \{{{PARTICLE_EVENT_VALUE}}} will receive this payload:

```
data:application/octet-stream;base64,pyKYHEAbm4C7ndnAE7tO0KPAroHFk5Eqg45pJ7DGFyaFk7em9WnATJ49U0m1R/BEJpuKHeS8c/lNpOg0wlYXyQ==
Expand All @@ -89,6 +89,9 @@ text and valid JSON, it is compatible with both the default webhook template, as
}
```

If you are using Logic, there are [data URL decoding functions](/getting-started/logic-ledger/logic/#dataurldecode)
included in Logic.

## Structured data

Particle has long-recommended using JSON format for sending data from your device to the cloud using Particle.publish.
Expand Down Expand Up @@ -214,11 +217,11 @@ This example sends binary data in a publish.

{{> codebox content="/assets/files/extended-publish/BinaryData.cpp" format="cpp" height="400" flash="true"}}

### Binary with JSON publish
### JSON with binary publish

This example includes JSON data that includes binary data.

{{> codebox content="/assets/files/extended-publish/BinaryWithJson.cpp" format="cpp" height="400" flash="true"}}
{{> codebox content="/assets/files/extended-publish/JsonWithBinary.cpp" format="cpp" height="400" flash="true"}}

### Simple publish callback

Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/newMenu.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
{
"dir": "typed-publish",
"title": "Typed publish"
"title": "Typed and extended publish"
},
{
"dir": "bluetooth-le",
Expand Down

0 comments on commit 467f48f

Please sign in to comment.