Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to enable WiFiEsp on Arduino Due and other SAM32 chips. #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/WiFiEsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ along with The Arduino WiFiEsp library. If not, see
#include "WiFiEspClient.h"
#include "WiFiEspServer.h"
#include "utility/EspDrv.h"
#include "utility/RingBuffer.h"
#include "utility/WifiEspRingBuffer.h"
#include "utility/debug.h"


Expand Down
18 changes: 12 additions & 6 deletions src/utility/EspDrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef enum

Stream *EspDrv::espSerial;

RingBuffer EspDrv::ringBuf(32);
WifiEspRingBuffer EspDrv::ringBuf(32);

// Array of data to cache the information related to the networks discovered
char EspDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}};
Expand Down Expand Up @@ -797,12 +797,18 @@ bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const char* startTag, co
if(idx==NUMESPTAGS)
{
// end tag found
ringBuf.getStr(outStr, strlen(endTag));
if( ringBuf.getLength() - strlen(endTag) <= outStrLen ) {
ringBuf.getStr(outStr, strlen(endTag));

// read the remaining part of the response
readUntil(2000);
// read the remaining part of the response
readUntil(2000);

ret = true;
ret = true;
} else {
LOGERROR(F("Buffer overflow in sendCmdGet"));
}


}
else
{
Expand Down Expand Up @@ -871,7 +877,7 @@ int EspDrv::sendCmd(const __FlashStringHelper* cmd, int timeout, ...)

va_list args;
va_start (args, timeout);
vsnprintf_P (cmdBuf, CMD_BUFFER_SIZE, (char*)cmd, args);
vsnprintf (cmdBuf, CMD_BUFFER_SIZE, (char*)cmd, args);
va_end (args);

espEmptyBuf();
Expand Down
4 changes: 2 additions & 2 deletions src/utility/EspDrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ along with The Arduino WiFiEsp library. If not, see
#include "IPAddress.h"


#include "RingBuffer.h"
#include "WifiEspRingBuffer.h"



Expand Down Expand Up @@ -304,7 +304,7 @@ class EspDrv


// the ring buffer is used to search the tags in the stream
static RingBuffer ringBuf;
static WifiEspRingBuffer ringBuf;


//static int sendCmd(const char* cmd, int timeout=1000);
Expand Down
20 changes: 11 additions & 9 deletions src/utility/RingBuffer.cpp → src/utility/WifiEspRingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/

#include "RingBuffer.h"
#include "WifiEspRingBuffer.h"

#include <Arduino.h>

RingBuffer::RingBuffer(unsigned int size)
WifiEspRingBuffer::WifiEspRingBuffer(unsigned int size)
{
_size = size;
// add one char to terminate the string
Expand All @@ -29,20 +29,20 @@ RingBuffer::RingBuffer(unsigned int size)
init();
}

RingBuffer::~RingBuffer() {}
WifiEspRingBuffer::~WifiEspRingBuffer() {}

void RingBuffer::reset()
void WifiEspRingBuffer::reset()
{
ringBufP = ringBuf;
}

void RingBuffer::init()
void WifiEspRingBuffer::init()
{
ringBufP = ringBuf;
memset(ringBuf, 0, _size+1);
}

void RingBuffer::push(char c)
void WifiEspRingBuffer::push(char c)
{
*ringBufP = c;
ringBufP++;
Expand All @@ -52,7 +52,7 @@ void RingBuffer::push(char c)



bool RingBuffer::endsWith(const char* str)
bool WifiEspRingBuffer::endsWith(const char* str)
{
int findStrLen = strlen(str);

Expand All @@ -77,9 +77,11 @@ bool RingBuffer::endsWith(const char* str)
return true;
}

unsigned int WifiEspRingBuffer::getLength() {
return ringBufP - ringBuf;
}


void RingBuffer::getStr(char * destination, unsigned int skipChars)
void WifiEspRingBuffer::getStr(char * destination, unsigned int skipChars)
{
int len = ringBufP-ringBuf-skipChars;

Expand Down
11 changes: 6 additions & 5 deletions src/utility/RingBuffer.h → src/utility/WifiEspRingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ along with The Arduino WiFiEsp library. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------*/

#ifndef RingBuffer_h
#define RingBuffer_h
#ifndef WifiEspWifiEspRingBuffer_h
#define WifiEspWifiEspRingBuffer_h


class RingBuffer
class WifiEspRingBuffer
{
public:
RingBuffer(unsigned int size);
~RingBuffer();
WifiEspRingBuffer(unsigned int size);
~WifiEspRingBuffer();

void reset();
void init();
void push(char c);
int getPos();
bool endsWith(const char* str);
void getStr(char * destination, unsigned int skipChars);
unsigned int getLength();


private:
Expand Down
2 changes: 1 addition & 1 deletion src/utility/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ along with The Arduino WiFiEsp library. If not, see
// 3: INFO: errors, warnings and informational (default)
// 4: DEBUG: errors, warnings, informational and debug

#define _ESPLOGLEVEL_ 3
#define _ESPLOGLEVEL_ 4


#define LOGERROR(x) if(_ESPLOGLEVEL_>0) { Serial.print("[WiFiEsp] "); Serial.println(x); }
Expand Down