Skip to content

Commit

Permalink
docs(api): update ndef record methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Dec 29, 2023
1 parent 211f663 commit 54d1faf
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 8 deletions.
179 changes: 178 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,7 @@ Adds a text record to the message.

```cpp
void addTextRecord(String text);
void addTextRecord(String text, String languageCode);
```
#### Example 1
Expand Down Expand Up @@ -1398,7 +1399,7 @@ void addMimeMediaRecord(String mimeType, const char *payload, unsigned short pay
#### Example
```cpp
message.addMimeMediaRecord("text/plain", "Hello world!", 12);
message.addMimeMediaRecord("text/plain", "Hello world!", 12); // 12 is the payload length
```

### Method: `addWiFiRecord`
Expand All @@ -1419,6 +1420,8 @@ String password = "Password";
message.addWiFiRecord(ssid, authentificationType, encryptionType, password);
```

See [WiFi authentication types](#wifi-authentication-types) and [WiFi encryption types](#wifi-encryption-types) for a list of all the types that can be used.

## Class NdefRecord

A `NdefRecord` object represents an NDEF record. An NDEF record is a data structure that contains data that is stored or transported in an NDEF message.
Expand Down Expand Up @@ -1666,6 +1669,152 @@ Serial.print("URI: ");
Serial.println(record.getUri());
```

### Method: `setPayload`

Set the payload of the record.

```cpp
void setPayload(String payload);
void setPayload(const char *payload, unsigned short payloadLength);
```
#### Example 1
```cpp
record.setPayload("Hello world!");
```

#### Example 2

```cpp
record.setPayload("Hello world!", 12);
```

### Method: `setPayloadLength`

Set the payload length of the record.

```cpp
void setPayloadLength(uint8_t payloadLength);
```
#### Example
```cpp
record.setPayloadLength(12);
```

### Method: `setHeaderFlags`

Set the header flags of the record.

```cpp
void setHeaderFlags(uint8_t headerFlags);
```
#### Example
```cpp
record.setHeaderFlags(0x00);
```

### Method: `setTypeLength`

Set the type length of the record.

```cpp
void setTypeLength(uint8_t typeLength);
```
#### Example
```cpp
record.setTypeLength(0x00);
```

### Method: `setRecordType`

Set the record type of the record.

```cpp
void setRecordType(uint8_t wellKnownType);
void setRecordType(String type);
```
#### Example 1
```cpp
record.setRecordType(NDEF_TEXT_RECORD_TYPE);
```

#### Example 2

```cpp
record.setRecordType("application/vnd.wfa.wsc");
```

### Method: `setStatus`

Set the status of the record.

```cpp
void setStatus(uint8_t status);
```
#### Example
```cpp
record.setStatus(NDEF_STATUS);
```

### Method: `setLanguageCode`

Set the language code of the record.

```cpp
void setLanguageCode(String languageCode);
```
#### Example
```cpp
record.setLanguageCode("en");
```

### Method: `getContentLength`

Get the content length of the record.

```cpp
unsigned short getContentLength();
```

#### Example

```cpp
Serial.print("Content length: ");
Serial.println(record.getContentLength());
```

### Method: `getContent`

Get the content of the record.

```cpp
const char *getContent();
```

#### Example

```cpp
Serial.print("Content: ");
for (int i = 0; i < record.getContentLength(); i++) {
Serial.print(record.getContent()[i], HEX);
Serial.print(" ");
}
Serial.println();
```

## Appendix

### URI prefixes
Expand Down Expand Up @@ -1710,3 +1859,31 @@ Here is a list of all the prefixes that can be used with the [`addUriRecord`](#m
| `0x21` | `urn:epc:raw:` |
| `0x22` | `urn:epc:` |
| `0x23` | `urn:nfc:` |

### WiFi authentication types

Here is a list of all the authentication types that can be used with the [`addWiFiRecord`](#method-addwifirecord) method.

| Authentication type | Meaning |
| --- | --- |
| `"OPEN"` | Open |
| `"WPA PERSONAL"` | WPA Personal |
| `"SHARED"` | Shared |
| `"WPA ENTERPRISE"` | WPA Enterprise |
| `"WPA2 ENTERPRISE"` | WPA2 Enterprise |
| `"WPA2 PERSONAL"` | WPA2 Personal |

Any other value will be interpreted as `UNKNOWN`.

### WiFi encryption types

Here is a list of all the encryption types that can be used with the [`addWiFiRecord`](#method-addwifirecord) method.

| Encryption type | Meaning |
| --- | --- |
| `"NONE"` | None |
| `"WEP"` | WEP |
| `"TKIP"` | TKIP |
| `"AES"` | AES |

Any other value will be interpreted as `UNKNOWN`.
12 changes: 6 additions & 6 deletions examples/NDEFSendMessage/NDEFSendMessage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ void setup() {
message.addTextRecord("Bonjour le monde!", "fr"); // French explicitly
message.addUriRecord("google.com"); // No prefix explicitly
message.addUriRecord("https://www.electroniccats.com"); // https://www. prefix explicitly
message.addUriRecord("tel:1234567890"); // The library can handle all the prefixes listed at https://github.com/ElectronicCats/ElectronicCats-PN7150/blob/refactor/API.md##uri-prefixes
String ssid = "Bomber Cat";
String authentificationType = "WPA2 PERSONAL";
String encryptionType = "AES";
String password = "Password";
message.addUriRecord("tel:1234567890"); // The library can handle all the prefixes listed at https://github.com/ElectronicCats/ElectronicCats-PN7150/blob/master/API.md#uri-prefixes
String ssid = "Bomber Cat"; // SSID of the WiFi network
String authentificationType = "WPA2 PERSONAL"; // Supported authentification types at https://github.com/ElectronicCats/ElectronicCats-PN7150/blob/master/API.md#wifi-authentication-types
String encryptionType = "AES"; // Supported encryption types at https://github.com/ElectronicCats/ElectronicCats-PN7150/blob/master/API.md#wifi-encryption-types
String password = "Password"; // Password of the WiFi network
message.addWiFiRecord(ssid, authentificationType, encryptionType, password);
message.addUriRecord("mailto:deimoshall@gmail.com");
message.addMimeMediaRecord("text/plain", "Hello world!", 12);
message.addMimeMediaRecord("text/plain", "Hello world!", 12); // Media-type as defined in RFC 2046
nfc.setSendMsgCallback(messageSentCallback);

Serial.println("Initializing...");
Expand Down
2 changes: 1 addition & 1 deletion src/NdefRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
// #define DEBUG
// #define DEBUG2
#define DEBUG3
// #define DEBUG3

class NdefRecord {
private:
Expand Down

0 comments on commit 54d1faf

Please sign in to comment.