Skip to content

Commit

Permalink
increase stability
Browse files Browse the repository at this point in the history
increase stability
  • Loading branch information
iot-playground committed Feb 20, 2015
1 parent a7064bd commit 56b522a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
46 changes: 30 additions & 16 deletions Esp8266EasyIoT/Esp8266EasyIoT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
V1.1 - additional data types
V1.0 - first version
Created by Igor Jarc <[email protected]>
Created by Igor Jarc
See http://iot-playground.com for details
Please use community fourum on website
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -62,7 +64,7 @@ void Esp8266EasyIoT::begin(void (*_msgCallback)(const Esp8266EasyIoTMsg &), int
//while(processesp() != E_IDLE) delay(1);

// wait some time
for(int i=0;i<500;i++)
for(int i=0;i<600;i++)
{
if (processesp() != E_IDLE)
delay(10);
Expand Down Expand Up @@ -106,22 +108,23 @@ void Esp8266EasyIoT::requestNodeId()

void Esp8266EasyIoT::requestTime(void (* _timeCallback)(unsigned long)) {
timeCallback = _timeCallback;
writeesp(build(msg, _nodeId, C_INTERNAL, I_TIME, NODE_SENSOR_ID, false).set(""));
//writeesp(build(msg, _nodeId, C_INTERNAL, I_TIME, NODE_SENSOR_ID, false).set(""));

_waitingCommandResponse = true;
_commandRespondTimer = millis();

//waitIdle();

if (processesp() != E_IDLE)
{
for(int i=0;i<30;i++)
{
if (processesp() == E_IDLE)
break;
delay(10);
}
}
sendinternal(build(msg, _nodeId, C_INTERNAL, I_TIME, NODE_SENSOR_ID, false).set(""));
_waitingCommandResponse = false;

//if (processesp() != E_IDLE)
//{
// for(int i=0;i<30;i++)
// {
// if (processesp() == E_IDLE)
// break;
// delay(10);
// }
//}
}


Expand Down Expand Up @@ -155,10 +158,12 @@ void Esp8266EasyIoT::sendinternal(Esp8266EasyIoTMsg &message)
{
//if (waitIdle() && writeesp(message))
// waitIdle();

resetPingTimmer();

if (processesp() != E_IDLE)
{
for(int i=0;i<30;i++)
for(int i=0;i<100;i++)
{
if (processesp() == E_IDLE)
break;
Expand All @@ -170,7 +175,7 @@ void Esp8266EasyIoT::sendinternal(Esp8266EasyIoTMsg &message)

if (processesp() != E_IDLE)
{
for(int i=0;i<30;i++)
for(int i=0;i<100;i++)
{
if (processesp() == E_IDLE)
break;
Expand Down Expand Up @@ -268,6 +273,7 @@ bool Esp8266EasyIoT::process()
debug(PSTR("Receive C_SET\n"));
resetPingTimmer();

_newMessage = false;
// Call incoming message callback if available
if (msgCallback != NULL) {
msgCallback(msg);
Expand All @@ -283,6 +289,8 @@ bool Esp8266EasyIoT::process()
// calclulate new CRC
ack.crc8();

debug(PSTR("ACK message\n"));
//sendinternal(ack);
if (writeesp(ack))
{
debug(PSTR("ACK message\n"));
Expand Down Expand Up @@ -335,6 +343,12 @@ bool Esp8266EasyIoT::process()
}


void Esp8266EasyIoT::setNewMsg(Esp8266EasyIoTMsg &msgnew)
{
msg = msgnew;
}


void Esp8266EasyIoT::setPingTimmer()
{
_pingTimmer = millis() - PING_TIME - 1;
Expand Down
7 changes: 6 additions & 1 deletion Esp8266EasyIoT/Esp8266EasyIoT.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
V1.1 - additional data types
V1.0 - first version
Created by Igor Jarc <[email protected]>
Created by Igor Jarc
See http://iot-playground.com for details
Please use community fourum on website
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -91,6 +93,9 @@ class Esp8266EasyIoT

void sendBatteryLevel(uint8_t level, bool ack=false);

void setNewMsg(Esp8266EasyIoTMsg &);


protected:
Esp8266EasyIoTMsg msg;
Esp8266EasyIoTMsg ack;
Expand Down
4 changes: 3 additions & 1 deletion Esp8266EasyIoT/Esp8266EasyIoTMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
V1.1 - additional data types
V1.0 - first version
Created by Igor Jarc <[email protected]>
Created by Igor Jarc
See http://iot-playground.com for details
Please use community fourum on website
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down
6 changes: 4 additions & 2 deletions Esp8266EasyIoT/Esp8266EasyIoTMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
V1.1 - additional data types
V1.0 - first version
Created by Igor Jarc <[email protected]>
Created by Igor Jarc
See http://iot-playground.com for details
Please use community fourum on website
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand All @@ -17,7 +19,7 @@
#endif


#define LIBRARY_VERSION "1.1"
#define LIBRARY_VERSION "1.3"
#define PROTOCOL_VERSION 2
#define MAX_MESSAGE_LENGTH 127
#define HEADER_SIZE 9
Expand Down

0 comments on commit 56b522a

Please sign in to comment.