Hi Filipe,
In the past I made a library for the ESP8266 that works with AT commands. I used the large array
for that since the string could be big.
Here are some code snippets from that library (it is also present in the Jallib release) called esp8266.jal. If more than 80 bytes are needed the library uses a large array. Due to the use of aliases the rest of the library does not 'know' if a regular array
or a large array is used. The last procedure reads the data until a CR is received. After that you can check the contents of the buffer.
-- We need to check the array size to determine if we need a larger array than
-- the one that normally fits in one bank. If so we include a library to handle
-- larger arrays.
if (ESP8266_MAX_RECEIVE_BUFFER <= 80) then
var byte esp8266_receive_buffer[ESP8266_MAX_RECEIVE_BUFFER]
else
const word LARGE_ARRAY_1_SIZE = ESP8266_MAX_RECEIVE_BUFFER
const word LARGE_ARRAY_1_VARIABLE_SIZE = 1 -- Array of bytes.
include large_array_1
alias esp8266_receive_buffer is large_array_1
end if
-- Global variable that indicates how many bytes are in the global ESP8266
-- receive buffer.
var word esp8266_bytes_received
-- Control ESP8266 via first USART.
include serial_hw_int_cts
-- Wait a certain time for a character to be receives and return TRUE when a
-- character was received and return the character. Note that once read,
-- from the serial buffer the character is gone.
function _esp8266_get_character(byte out character) return bit is
var dword waittime = _ESP8266_RESPONSE_TIMEOUT_10_US
var bit character_received = FALSE
while !character_received & (waittime > 0) loop
if serial_hw_read(character) then
character_received = TRUE
end if
_usec_delay(10) -- Do not wait too long since bitrate is high.
waittime = waittime - 1
end loop
return character_received
end function
-- Copy the EPS8266 data from the serial buffer to the global EPS8266 receive
-- buffer until a carriage return is received. The number of copied bytes is
-- returned in the global variable esp8266_bytes_received
procedure _esp8266_copy_response() is
var byte character
var bit stop
stop = FALSE
esp8266_bytes_received = 0
while !stop & (esp8266_bytes_received < ESP8266_MAX_RECEIVE_BUFFER) loop
-- Getting the character is a one time read so stop as soon as it is over.
if _esp8266_get_character(character) then
if (character == _ESP8266_CARRIAGE_RETURN) then
stop = TRUE
else
esp8266_receive_buffer[esp8266_bytes_received] = character
esp8266_bytes_received = esp8266_bytes_received + 1
end if
else
stop = TRUE
end if
end loop
end procedure
Kind regards,
Rob