Specifications

Specification: Message format CODEC_SPEC_1 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_REQ_1

The message format is NDEF. This is used to transmit data to a phone using NFC. An NDEF message has 3 fields: Type, Length and Value.

NDEF Msg.

NDEF message type (CODEC_FEAT_1)

NDEF message length (CODEC_FEAT_2)

Value

Byte

0

1

2

3

4…

Data

0x03

0xFF

MSB

LSB

NDEF URL record (CODEC_SPEC_3)

Specification: NDEF URL record CODEC_SPEC_3 ../../_images/arrow-right-circle.svg

Sensor data are stored in a URL record. As it is the only one in the message and of a known type, a phone opens the URL automatically in its default web browser.

NDEF record header

Desc

TNF + flags (CODEC_SPEC_5)

Type length (CODEC_FEAT_4)

Payload length (CODEC_FEAT_3)

Record type (CODEC_FEAT_5)

Byte

0

1

2

3

4

5

6

Data

0xC3

0x01

PL[3]

PL[2]

PL[1]

PL[0]

0x55

NDEF record payload start

Desc.

Protocol (CODEC_FEAT_44)

Base URL (CODEC_FEAT_7)

Sample interval b64 (CODEC_FEAT_10)

Serial (CODEC_FEAT_38)

Data

0x03

t.plotsensor.com

/?t=AWg*

&s=YWJjZGVm

NDEF record payload continued

Desc.

VFmt b64 (CODEC_SPEC_18)

Status b64 (CODEC_SPEC_15)

CircBufferStart

Circular Buffer (CODEC_SPEC_12)

Data

&v=AAAA

&x=AAABALEK

&q=

MDaWMDaW…

Specification: Circular Buffer CODEC_SPEC_12 ../../_images/arrow-right-circle.svg
status: complete

The circular buffer starts on a block boundary and occupies an integer number of 16-byte blocks. 1K of EEPROM is enough for 32 blocks.

Only two blocks are edited in RAM at a time:

Cursor Block

Next Block

Cursor Demi

Endstop Demis (0,1)

Oldest Demi

P641

P640

P64N

P64N-1

R643

R642

R641

R640

R64L

R64L-1

R64L-2

R64L-3

Blocks are subdivided into two 8-byte demis. Each demi holds 2 base64 encoded pairs.

Each pair consists of 2 base64 encoded sensor readings. By default these will be captured simultaneously by a temperature sensor and a humidity sensor.

New sensor readings are written to Cursor Demi. Each time this occurs, the subsequent Endstop (CODEC_SPEC_13) is updated.

When Cursor Demi is full, both it and the endstop are moved forward when the next sensor reading is added:

Cursor Block

Next Block

Demi

Cursor Demi

Endstop Demis (0,1)

S2

S1

S0

Spad

R5

R4

R3

R2

R1

R0

The previous oldest demi is overwritten. Note there can be a gap between the most recent sample and the start of the endstop demis. This is zero padded. The padding will not be decoded because the number of valid samples in the buffer is included in the endstop.

Specification: Endstop CODEC_SPEC_13 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_SPEC_12
links incoming: CODEC_FEAT_26, CODEC_SPEC_14

The endstop occupies 2 demis (16 bytes) after the cursor demi. It is terminated with a unique character. This marks the end of the circular buffer; the divide between new and old data. The decoder finds this in order to unwrap the circular buffer into a list of samples, ordered newest to oldest.

The endstop contains data about the current state of the circular buffer, for example the number of valid samples it contains. These data are appended to the circular buffer to meet Reduce EEPROM wear (CODEC_SPEC_2).

Specification: VFmt b64 CODEC_SPEC_18 ../../_images/arrow-right-circle.svg
status: open
links outgoing: CODEC_SPEC_3
links incoming: CODEC_FEAT_41, CODEC_FEAT_42

This is a 3 byte structure that expands to 4 bytes after base64 encoding.

The unencoded structure is:

Byte

0

1

2

Description

CodecVersion (CODEC_FEAT_41)

FormatCode (CODEC_FEAT_42)

Specification: HashN b64 CODEC_SPEC_14 ../../_images/arrow-right-circle.svg
status: complete
links outgoing: CODEC_SPEC_13
links incoming: CODEC_FEAT_24, CODEC_FEAT_25

This is a 9 byte structure that expands to 12 bytes after base64 encoding.

The unencoded structure is:

Byte

0

1

2

3

4

5

6

7

8

Description

Hash (CODEC_FEAT_24)

NPairs (CODEC_FEAT_25)

Specification: Status b64 CODEC_SPEC_15 ../../_images/arrow-right-circle.svg
status: complete

This is a 6 byte structure that expands to 8 bytes after base64 encoding.

It corresponds to status. Status information is used by the decoder to determine if the encoder and its microcontroller host are running ok.

The unencoded structure is:

Byte

0

1

2

3

4

5

Description

LoopCount (CODEC_FEAT_28)

ResetsAllTime (CODEC_FEAT_29)

BatV (CODEC_FEAT_30)

ResetCause (CODEC_SPEC_16)

Specification: ResetCause CODEC_SPEC_16 ../../_images/arrow-right-circle.svg

Flags to indicate causes of the most recent microcontroller reset.

Bit

0

1

2

3

4

5

6

7

Description

BOR (CODEC_FEAT_31)

SVSH (CODEC_FEAT_32)

WDT (CODEC_FEAT_33)

MISC (CODEC_FEAT_34)

LPM5WU (CODEC_FEAT_35)

CLOCKFAIL (CODEC_FEAT_36)

SCANTIMEOUT (CODEC_FEAT_37)

Specification: TNF + flags CODEC_SPEC_5 ../../_images/arrow-right-circle.svg
status: complete

TNF and flags for the NDEF record.

Bit

7

6

5

4

3

2

1

0

Field

MB (CODEC_FEAT_17)

ME (CODEC_FEAT_18)

CF (CODEC_FEAT_19)

SR (CODEC_FEAT_20)

IL (CODEC_FEAT_21)

TNF (CODEC_FEAT_22)

Data

1

1

0

0

0

0x03

Specification: Low memory utilisation CODEC_SPEC_4 ../../_images/arrow-right-circle.svg
status: open

The encoder must use <2K of RAM and <16K of non-volatile FRAM, as can be found on an MSP430FR2033 microcontroller.

Specification: Reduce EEPROM wear CODEC_SPEC_2 ../../_images/arrow-right-circle.svg
status: open
links outgoing: CODEC_REQ_8
links incoming: CODEC_FEAT_16, CODEC_SPEC_12
Specification: Low power consumption CODEC_SPEC_8 ../../_images/arrow-right-circle.svg
status: open
links outgoing: CODEC_REQ_12
links incoming: CODEC_FEAT_14, CODEC_FEAT_16

The encoder will run for >2 years on a hardware powered by a CR1620 battery.

Specification: Zero user configuration CODEC_SPEC_6 ../../_images/arrow-right-circle.svg
links outgoing: CODEC_REQ_7
links incoming: CODEC_FEAT_27

The encoder must run without input from the user. This includes after the Power-on-Reset when a battery is replaced.

Specification: URL parameters decoded CODEC_SPEC_19 ../../_images/arrow-right-circle.svg
links outgoing: CODEC_REQ_2
links incoming: CODEC_FEAT_43, CODEC_SPEC_10

Before the circular buffer is decoded, URL parameters such as VFmt b64 (CODEC_SPEC_18) are needed.

Specification: Circular buffer decoded CODEC_SPEC_10 ../../_images/arrow-right-circle.svg
links outgoing: CODEC_SPEC_19

The decoder outputs a list of samples from the URL. Output depends on FormatCode (CODEC_FEAT_42). By default samples will contain temperature and humidity readings, converted to degrees C and percent respectively. Each will have a timestamp precise to one minute. This corresponds to the time that the sample was added to the circular buffer.