hi defragster,
Thanks for your response and your suggestions!
Perhaps at key points in loop starting a variable uint32_t runLine = __LINE__;
> that runLine might indicate where it is stopping if saved/printed.
i have done something similar with my logging macros. Let me explain the log lines a bit more in detail. I should have done that way earlier...
A log line usually looks like this:
Code:
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 951] handle | Handle existing clients ...OK
| | | | | | +-> User defined message
| | | | | +-> Function name
| | | | +-> Line #
| | | +-> Filename
| | +-> Date/Time
| +-> elapsed Millis
+-> Log Level
The "loop" function looks like this: (i have left out irrelevant functions behind commented out defines)
HAP_DEBUG is set to 1
HAP_HEAP_LOG_INTERVAL is set to 5
The LOGRAW_V("OK\n"); in the code below printfs just the user defined message.
LOG_HEAP() printfs out the current heap, freemen and maxstack value like this
Code:
[H] 31416812 | 2021-07-25 07:42:28 | HAPServer.cpp [ 929] handle | heap:383960 | mem:113668 | stack:113696 | clients: 0 | queue: 0
The heap, mem and stack values are constant throught the last 500 lines of the log. There aren't so many statements
Code:
void HAPServer::handle() {
#if HAP_DEBUG
// Free Heap every interval ms
if ( millis() - _previousMillisHeap >= HAP_HEAP_LOG_INTERVAL) {
_previousMillisHeap = millis();
LOG_HEAP(_clients.size(), _eventManager.getNumEventsInQueue());
}
#endif
//
// Handle existing clients
//
LOG_V("Handle existing clients ...");
for (auto& hapClient : _clients) {
// Connected
if (hapClient->client.connected()) {
// Available
unsigned long timeout = 15;
unsigned long previousMillis = millis();
while ( millis() - previousMillis < timeout) {
if (hapClient->client.available()) {
hapClient->state = HAPClientState::Available;
handleClientState(hapClient);
break;
}
// Idle
hapClient->state = HAPClientState::Idle;
}
} else {
// Disconnected
hapClient->state = HAPClientState::Disconnected;
handleClientState(hapClient);
}
}
LOGRAW_V("OK\n");
//
// Handle new clients
//
LOG_V("Checking for new clients ...");
EthernetClient client = _server.available();
if (client) {
LOGRAW_V("OK\n");
LOG_V("Handle new client ...");
HAPClient* hapClient = new HAPClient();
// New client connected
hapClient->client = client;
hapClient->state = HAPClientState::Connected;
handleClientState(hapClient);
}
LOGRAW_V("OK\n");
//
// Handle plugins
//
LOG_V("Handling plugins ...");
for (auto& plugin : _plugins){
if ( plugin && plugin->isEnabled() ){
plugin->handle();
}
}
LOGRAW_V("OK\n");
//
// Handle fakeGatos
//
LOG_V("Handling Fakegato ...");
_fakeGatoFactory.handle();
LOGRAW_V("OK\n");
//
// Handle any events that are in the queue
//
LOG_V("Handling Events ...");
processEvents();
LOGRAW_V("OK\n");
}
I have no connection from a client, so blocks using a client or hapclient shouldn't cause any trouble.
Remains the handling of plugins, fakegatos and events. I will have at look at this and check for similar dependencies regarding pointers or the like.
And the heap logging itself... hmm. I will disable this and have another test in the meanwhile.
Additionally here is a summary of the logs of my tests:
Code:
Summary:
Runtime from 2021-07-19-23:09:10 to 2021-07-20-11:07:52
Duration: 11:58:41.816272
Last Lines:
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 947] handle | Handle existing clients ...OK
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 1025] handle | Handling plugins ...OK
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 1043] handle | Handling Events ...OK
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 986] handle | Checking for new clients ...OK
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 1036] handle | Handling Fakegato ...OK
[V] 43388043 | 2021-07-20 11:07:49 | HAPServer.cpp [ 947] handle | Handle existing clients ...OK
Summary:
Runtime from 2021-07-20-15:29:56 to 2021-07-20-21:01:02
Duration: 5:31:06.224646
Last Lines:
[V] 21600375 | 2021-07-20 21:01:01 | HAPServer.cpp [ 947] handle | Handle existing clients ...OK
[V] 21600375 | 2021-07-20 21:01:01 | HAPServer.cpp [ 1025] handle | Handling plugins ...OK
[V] 21600375 | 2021-07-20 21:01:01 | HAPServer.cpp [ 1043] handle | Handling Events ...OK
[V] 21600375 | 2021-07-20 21:01:01 | HAPServer.cpp [ 986] handle | Checking for new clients ...OK
[V] 21600375 | 2021-07-20 21:01:01 | HAPServer.cpp [ 1036] handle | Handling Fakegato ...[D] 21600376 | 2021-07-20 21:01:01 | HAPFakegato.cpp [ 147] addDataToBuffer | Adding entry for 0CD851-BME280-DUMMY [size=100 bitmask=7] - data length: 6
OK
[V] 21600376 | 2021-07-20 21:01:01 | HAPServer.cpp [ 947] handle | Handle existing clients ...OK
[V] 21600376 | 2021-07-20 21:01:01 | HAPServer.cpp [ 1025] handle | Handling plugins ...[V] 21600376 | 2021-07-20 21:01:01 | HAPPluginBME280.cpp [ 134] handleImpl | [BME280] - Handle plugin [1]
[I] 21600376 | 2021-07-20 21:01:01 | HAPPluginBME280.cpp [ 126] changedHumidity | [BME280] Changed humidity: 23.00 >>> 36.00
OK
Summary:
Runtime from 2021-07-20-22:38:15 to 2021-07-20-22:39:26
Duration: 0:01:10.672179
Last Lines:
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 945] handle | Handle existing clients ...OK
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 1023] handle | Handling plugins ...OK
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 1041] handle | Handling Events ...OK
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 984] handle | Checking for new clients ...OK
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 1034] handle | Handling Fakegato ...OK
[V] 75629 | 2021-07-20 22:39:25 | HAPServer.cpp [ 945] handle | Handle existing clients ...OK
Summary:
Runtime from 2021-07-20-23:52:02 to 2021-07-23-00:12:39
Duration: 2 days, 0:20:36.867410
Last Lines:
[V] 178465933 | 2021-07-23 00:12:37 | HAPServer.cpp [ 984] handle | Checking for new clients ...OK
[V] 178465933 | 2021-07-23 00:12:37 | HAPServer.cpp [ 1034] handle | Handling Fakegato ...OK
[V] 178465933 | 2021-07-23 00:12:37 | HAPServer.cpp [ 945] handle | Handle existing clients ...OK
[V] 178465933 | 2021-07-23 00:12:37 | HAPServer.cpp [ 1023] handle | Handling plugins ...OK
[V] 178465933 | 2021-07-23 00:12:37 | HAPServer.cpp [ 1041] handle | Handling Events ...[340 >>> 35.80
Summary:
Runtime from 2021-07-24-08:00:50 to 2021-07-24-12:50:10
Duration: 4:49:19.402888
Last Lines:
[V] 17362204 | 2021-07-24 12:50:08 | HAPServer.cpp [ 1041] handle | Handling Events ...OK
[V] 17362204 | 2021-07-24 12:50:08 | HAPServer.cpp [ 984] handle | Checking for new clients ...OK
[V] 17362206 | 2021-07-24 12:50:08 | HAPServer.cpp [ 1023] handle | Handling plugins ...OK
[V] 17362206 | 2021-07-24 12:50:08 | HAPServer.cpp [ 1041] handle | Handling Events ...OK
[V] 17362206 | 2021-07-24 12:50:08 | HAPServer.cpp [ 984] handle | Checking for new clients ...OK
[V] 17362206 | 2021-07-24 12:50:08 | HAPServer.cpp [ 1034] handle | Handling Fakegato ...OK
Summary:
Runtime from 2021-07-24-22:58:59 to 2021-07-25-07:42:32
Duration: 8:43:32.960555
Last Lines:
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 1047] handle | Handling Events ...OK
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 951] handle | Handle existing clients ...OK
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 1029] handle | Handling plugins ...OK
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 1047] handle | Handling Events ...OK
[V] 31419654 | 2021-07-25 07:42:31 | HAPServer.cpp [ 951] handle | Handle existing clients ...OK