Environmental Sensor Pal AMBIENT SENSE PAL is used to acquire sensor values.
This ACT includes
Sending and receiving wireless packets
Configuring settings via Interactive settings mode - <STG_STD>
State transition control by state machine - <SM_SIMPLE>
<PAL_AMB>Board operation with board behavior
Uses the environmental sensor PAL AMPIENT SENSE PAL to acquire sensor values.
Use the sleep function to operate with coin cell batteries.
Role | Example |
---|---|
Environment sensor pal <PAL_AMB>
) include board behavior.
The first step is to initialize variables, etc. Here we are initializing the state machine step.
First, the board support <PAL_AMB>
is registered. The sensors and DIOs are initialized when the board support is initialized. The reason for doing this first is that it is common to check the status of the board's DIP SW, etc., and then configure network settings, etc.
The next step is to initialize and read out the Interactive settings mode.
Here you can get the set object, reflect the application name, reflect the default Application ID, and delete unnecessary items in the settings menu.
Next, the state of the SET pin is read. Since this sample operates intermittently in sleep mode, Interactive settings mode transition by +++ input is not possible. Instead, the sample transitions to Interactive settings mode with the SET pin = LO state at startup. In this case, SETTINGS::open_at_start()
is specified, which means that the interactive mode screen will be displayed as soon as setup()
is finished.
Finally, .reload()
is executed to read the set values from the EEPROM. The configuration values are copied to each variable.
Next, configure the LED settings. (In an application that sleeps and wakes for a short period of time, this is almost the same as setting the LED to turn on during wake-up.)
Since this ACT exclusively transmits wireless packets, the TWENET configuration does not include a specification (TWENET::rx_when_idle()
) to open the receive circuit during operation.
The sensors on the board use the I2C bus, so start using the bus.
Starts the acquisition of a sensor on the board. See the description of startSensorCapture()
.
The loop()
is controlled by the SMSMSIMPLE_SIMPLE state machinestep
for control. This is to concisely represent the sequence of events from sleep recovery, sensor value acquisition, wireless packet transmission, waiting for transmission to complete, and sleep. In the combat of the loop, a brd
object is acquired.
It is not convenient to have the main loop running during Interactive settings mode, so it is fixed in this state.
Start sensor data acquisition.
The sensors on the board can be accessed with the name .sns_LTR308ALS
or .sns_SHTC3
, and operations are performed on this object. Wait for the sensor to complete. If the sensor has not yet been acquired (.available()
is false
), a time elapsed event (.process_ev(E_EVENT_TICK_TIMER)
) is sent to the sensor.
When the above two sensors become available, the sensor value is retrieved and a transition is made to STATE TOK_TX.
The illuminance sensor can be obtained with .get_luminance() : uint32_t
.
The temperature and humidity sensor can be obtained as follows.
.get_temp_cent()
: int16_t
: temperature with 1℃ as 100 (2560 for 25.6℃)
.get_temp()
: float
: float value (25.6 for 25.6 ℃)
.get_humid_dmil()
: int16_t
: humidity at 1% as 100 (5680 for 56.8%)
.get_temp()
: float
: float value (56.8 for 56.8%)
The transmission procedure is the same as in the other ACT samples. Here, the settings are set to minimize one retransmission and retransmission delay.
The identifier FOURCHARS
and the sensor data are stored in the payload part of the packet. Of the values obtained, the temperature value is int16_t
, but is cast to uint16_t
because the data structure of the outgoing packet is to be stored unsigned.
Requests transmission. If the send request succeeds, prepare the send completion city. Specify .clear_flag()
to wait for the completion event and set_timeout(100)
for timeout in case of emergency. The unit of 100 in the parameter is milliseconds [ms].
This section determines timeouts and transmission completion events.
Processes sleepNow()
.
This is a system event called when transmission is complete. Here, .set_flag()
is used to indicate completion.
This section includes a collection of procedures for going to sleep.
Initialize the state of the state machine by .on_sleep(false)
before sleep. The parameter false' starts from
STATE::INIT(=0)` after returning from sleep.
Here, the time to wake up is set between 1750ms and 2250ms by a random number. This avoids continuous collisions with packets from other devices transmitting at a similar period.
If the cycles are exactly the same, packets from each other will collide and communication will be difficult. Usually, the timer cycles shift with each other over time, so that communication is restored after a short period of time, and then collisions occur again after another period of time.
Lines 8 and 9, this example goes to sleep waiting for output from the serial port. Usually, we want to minimize energy consumption, so we minimize (or eliminate) output from the serial port before sleep.
Line 12, to enter sleep, call the_twelite.sleep()
. In this call, the pre-sleep procedures of the hardware on the board are performed. For example, LEDs are turned off.
The sleep time is specified in ms as a parameter.
TWELITE PAL must always wake up once within 60 seconds to reset the watchdog timer. The sleep time must be specified not to exceed 60000
.
When the program wakes up from sleep, wakeup()
is called. After that, loop()
is called each time. Before wakeup()
, each peripheral such as UART and devices on the board are woken up. For example, it restarts the LED lighting control.
ACT PAL_AMB-UseNap can operate with lower energy consumption by sleeping while waiting for sensor data acquisition.
Parent Node
MONOSTICK BLUE or RED ACT Parent_MONOSTICK in action.
Child Node