In this page we present a customization, called TerraEsp, that is a very light customization for ESP8266-12F Board using only simple radio communications and GPIO.
This Terra customization mainly provides only very basic "send" and "receive" events and GPIO operations. Table 1 presents the current TerraEsp events interface and Table 2 presents the functions interface.
Some code examples are presented at the end.
The local operations comprises operations to access input and output devices of the microcontroller. Terra encapsulates all these operations in a component called Local Operations providing them as input and/or output events. Timers, on the other hand, are handled directly by the Céu-T language with the await time command.
The SEND() command is a basic send command where only the nodes in the local network may receive the message. If the field target is set to BROADCAST value, all nodes in the local network will receive the message. On the other hand, if this field is set to a specific node identifier, only this node will receive the message (if the node is in the local network). A SEND_DONE() event indicates that the send request was processed by the radio. The RECEIVE event returns a received message. A variation of the SEND() command is the SEND_ACK() command that requests an acknowledgement from the target mote. In this variation the SEND_DONE_ACK() event return a boolean value indicating the acknowledgement. Additionally, TerraEsp implements a simple message queue to support message buffering needs.
The user must define the radio message data structure before create a message variable.
Description | Output event (emit) | Input event (await) | |||
---|---|---|---|---|---|
Event identifier | Argument type | Returned type | Event identifier | Argument type | |
Custom event - This is a internal loopback event that allows to pass a integer value. The await command may define or not which value to wait. | REQ_CUSTOM_A | ubyte | ubyte | CUSTOM_A | void or ubyte |
Send radio message - Sends a radioMsg variable (broadcast or to a specific target node). | SEND | radioMsg | ubyte | SEND_DONE | void or ubyte |
Send radio message (with Acknowledgement) - Sends a radioMsg variable to a specific target node requesting an acknowledgment. The confirmation (TRUE or FALSE) is returned in the SEND_DONE_ACK. | SEND_ACK | radioMsg | ubyte | SEND_DONE_ACK | void or ubyte |
Receive radio message - returns a radioMsg variable received by the radio. The argument may be used to wait only a specific message type identifier. | radioMsg | RECEIVE | void or ubyte | ||
Message queue - This event indicates that the msg queue got a new element when it was empty. | ubyte | Q_READY | void | ||
Error trap - Indicates a internal errors like E_DIVZERO and E_IDXOVF, respectively division by zero and array index overflow. | ubyte | ERROR | void or ubyte | ||
Analog Input - Requests and receives the analog input value. The received value is a 10bit reading from Analog to Digital converter. | REQ_AN0 | void | ushort | ANA0 | void |
GPIO Interrupt fired. Must be configured by specific functions. Returns always 0 | ubyte | GPIO_INT | void |
Description | Returned type | Function name | arguments |
---|---|---|---|
Return the node identifier | ushort | getNodeId | void |
Return a 16bits random number | ushort | random | void |
Return the internal timer counter in milliseconds | ulong | getTime | void |
Put a radioMsg data into the queue. The message structure is passed as argument. Returns FAIL if the queue is full, otherwise returns SUCCESS. | ubyte | qPut | radioMsg msgVar |
Get a radioMsg data from the queue. The message structure is passed as argument. Returns FAIL if the queue is empty, otherwise returns SUCCESS. | ubyte | qGet | radioMsg msgVar |
Return the queue size | ubyte | qSize | void |
Clear all queue entries. Always returns SUCCESS. | ubyte | qClear | void |
Set the radio transmit power level. Always returns SUCCESS. | ubyte | setRFPower | ubyte level |
Set the pin mode INPUT, OUTPUT, OUTPUT_HIGH. Always returns SUCCESS. The two arguments are: gpio_no, mode. See constants definitions for more details. | ubyte | pinMode | ubyte,ubyte |
Writes LOW or HIGH to a pin. Always returns SUCCESS. The two arguments are: gpio_no, value. See constants definitions for more details. Note: Writing to a pin configured as INPUT, will change the pin configuration to OUTPUT. | ubyte | pinWrite | ubyte,ubyte |
Returns the input value of a pin. The argument is: gpio_no. See constants definitions for more details. | ubyte | pinRead | ubyte,ubyte |
Toggle the pin value. Always returns SUCCESS. The two arguments are: port_id, pin_id. See constants definitions for more details. | ubyte | pinToggle | ubyte |
Enable the GPIO interrupt. Always returns SUCCESS. | ubyte | intEnable | void |
Disable the GPIO interrupt. Always returns SUCCESS. | ubyte | intDisable | void |
Configure the interrupt mode for a specific GPIO pin. Always returns SUCCESS. The arguments are the gpio_no and the mode - INT_DISABLE, INT_POSEDGE, INT_NEGEDGE, or INT_ANYEDGE. | ubyte | intConfig | ubyte, ubyte |
Constant | Value | Description |
---|---|---|
SUCCESS | 0 | Indicates a Success operation |
TRUE | 1 | A true value |
FALSE | 0 | A false value |
ON | 1 | Set GPIO HIGH |
OFF | 0 | Set GPIO LOW |
TOGGLE | 2 | Set GPIO with opposite value |
BROADCAST | 0xffff | Define a broadcast message |
E_DIVZERO | 10 | Error event - Division by zero |
E_IDXOVF | 11 | Error event - Array index overflow |
E_STKOVF | 20 | Error event - Stack overflow -- fatal |
LOW | 0 | A digital low value |
HIGH | 1 | A digital high value |
INPUT | 0 | Defines the input mode for a digital pin |
OUTPUT | 1 | Defines the output mode for a digital pin and set its value as LOW. |
OUTPUT_HIGH | 1 | Defines the output mode for a digital pin and set its value as HIGH. |
INT_DISABLE | 0 | Disable any interrupt from the specified gpio_no |
INT_POSEDGE | 1 | Interrupt mode: Interrupts at rising edge - 0->1 |
INT_NEGEDGE | 2 | Interrupt mode: Interrupts at falling edge - 1->0 |
INT_ANYEDGE | 3 | Interrupt mode: Interrupts when the input toggles its value |
GPIO0 .. GPIO5 , GPIO12 .. GPIO16 | 0 .. 5, 12 .. 16 | GPIO number - gpio_no. Note: Only few GPIO pins are available in the board. |
#include "TerraEsp.defs"
pinMode(GPIO12,OUTPUT); // GPIO12 pin as output
loop do
await 500ms; // Waits 0,5 seconds
pinToggle(GPIO12); // Toggle LED value
end
Connect a push button to GND and GPIO5. Connect a 10Kohms resistor to 3.3v and GPIO5. The LED at GPIO12 will toggle once when you press the button. Do nothing when releasing it.
#include "TerraEsp.defs"
pinMode(GPIO12,OUTPUT); // GPIO12 pin as output
pinMode(GPIO5,INPUT); // GPIO5 pin as input
intPinConfig(GPIO5,INT_NEGEDGE); // GPIO5 Interrupts from 1 to 0.
intEnable(); // Enable all GPIO interruptions.
loop do
await GPIO_INT(); // Waits for any configured GPIO interrupt.
pinToggle(GPIO12); // Toggle the LED status
await 30ms; // Debouncing: Waits some time before next Interruption.
end