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

Improve logging #155

Merged
merged 27 commits into from
May 25, 2021
Merged

Improve logging #155

merged 27 commits into from
May 25, 2021

Conversation

kadaan
Copy link
Contributor

@kadaan kadaan commented Mar 26, 2021

Add sending to telegram back (not optimal ATM, creates too many strings)
Remove config file logging to not expose secrets
Merge with develop

# Conflicts:
#	.gitignore
#	include/BLE_Common.h
#	include/Builtin_Pages.h
#	include/Main.h
#	include/SmartSpin_parameters.h
#	include/sensors/CyclePowerData.h
#	include/sensors/FitnessMachineIndoorBikeData.h
#	include/sensors/HeartRateData.h
#	include/sensors/SensorDataFactory.h
#	include/settings.h
#	platformio.ini
#	src/BLE_Client.cpp
#	src/BLE_Common.cpp
#	src/BLE_Server.cpp
#	src/BLE_Setup.cpp
#	src/HTTP_Server_Basic.cpp
#	src/Main.cpp
#	src/SmartSpin_parameters.cpp
#	src/sensors/FitnessMachineIndoorBikeData.cpp
#	src/sensors/SensorDataFactory.cpp

Add sending to telegram back (not optimal ATM, creates too many strings)
Remove config file logging to not expose secrets
Merge with develop

# Conflicts:
#	.gitignore
#	include/BLE_Common.h
#	include/Builtin_Pages.h
#	include/Main.h
#	include/SmartSpin_parameters.h
#	include/sensors/CyclePowerData.h
#	include/sensors/FitnessMachineIndoorBikeData.h
#	include/sensors/HeartRateData.h
#	include/sensors/SensorDataFactory.h
#	include/settings.h
#	platformio.ini
#	src/BLE_Client.cpp
#	src/BLE_Common.cpp
#	src/BLE_Server.cpp
#	src/BLE_Setup.cpp
#	src/HTTP_Server_Basic.cpp
#	src/Main.cpp
#	src/SmartSpin_parameters.cpp
#	src/sensors/FitnessMachineIndoorBikeData.cpp
#	src/sensors/SensorDataFactory.cpp
@kadaan kadaan marked this pull request as draft March 26, 2021 00:50
@kadaan kadaan requested a review from doudar March 26, 2021 19:02
@kadaan kadaan marked this pull request as ready for review March 26, 2021 19:02
@doudar
Copy link
Owner

doudar commented Mar 27, 2021

I'm guessing you couldn't find a good precompiler based solution instead of writing the filename in every SS2K_LOG() call?

I see a possible way of doing it but it looks like it's runtime, so yuck...

https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

@doudar
Copy link
Owner

doudar commented Mar 27, 2021

Got through a bunch of it tonight. I'll continue in the morning.

One concern - is there a switch for logging to Spiffs? It's probably pretty crappy flash memory and might wear out if we do a lot of writes.

Also, I don't know yet if you have any space checking before you append to the file (don't want to fill up spiffs).

Another thing I just thought of, if the file gets very large, I read somewhere that spiffs write appends can get very slow (like tens of seconds) if the file gets more than a few kb in size.

espressif/arduino-esp32#1360

@kadaan
Copy link
Contributor Author

kadaan commented Mar 27, 2021

@doudar I’m not logging to SPIFFS and didn’t plan to support that.

Copy link
Owner

@doudar doudar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a crash when a shift happens.

src/SS2KLog.cpp Show resolved Hide resolved
@doudar
Copy link
Owner

doudar commented Apr 7, 2021

Looks like there's a crash when a shift happens.

Any updates?

kadaan added 12 commits April 6, 2021 21:58
# Conflicts:
#	src/BLE_Server.cpp
# Conflicts:
#	src/BLE_Common.cpp
#	src/SmartSpin_parameters.cpp
Fix calls to pio docker container
# Conflicts:
#	.github/workflows/pre-commit.yml
#	.pre-commit-config.yaml
#	CHANGELOG.md
#	lib/SS2K/include/sensors/CyclePowerData.h
#	lib/SS2K/src/sensors/FitnessMachineIndoorBikeData.cpp
#	lib/SS2K/src/sensors/SensorDataFactory.cpp
#	platformio.ini
#	src/BLE_Common.cpp
#	src/HTTP_Server_Basic.cpp
@doudar
Copy link
Owner

doudar commented May 14, 2021

Progress 👍

I'm studying tonight - review will happen tomorrow.

Have you done any ride testing yet?

@kadaan kadaan force-pushed the Improve_logging branch from 1145311 to b4590af Compare May 25, 2021 02:48
@doudar
Copy link
Owner

doudar commented May 25, 2021

Lgtm

@kadaan kadaan merged commit 9b3dec6 into doudar:develop May 25, 2021
@kadaan kadaan deleted the Improve_logging branch May 25, 2021 15:34
@doudar doudar mentioned this pull request May 26, 2021
@doudar
Copy link
Owner

doudar commented May 26, 2021

@kadaan Make sure to restore this branch (it's in your repo so I can't).

I obviously love the output but I didn't pay attention previously to the lengthy process involved to generate logging in the BLE_Server code. It would be too laborious and obscure to insert the proposed logging into every case statement for the soon to be incoming FTMS_Server-fillout as well as future changes.

We need to get

  const int kLogBufMaxLength = 200;
  char logBuf[kLogBufMaxLength];
  int logBufLength = ss2k_log_hex_to_buffer(ftmsIndoorBikeData, *(&ftmsIndoorBikeData + 1) - ftmsIndoorBikeData, logBuf, 0, kLogBufMaxLength);
  logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, "-> %s | %s | FTMS(IBD)[", FITNESSMACHINESERVICE_UUID.toString().c_str(),
                           fitnessMachineIndoorBikeData->getUUID().toString().c_str());
  logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, " HR(%d)", hr % 1000);
  logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, " CD(%.2f)", fmodf(cadRaw, 1000.0));
  logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, " PW(%d)", watts % 10000);
  logBufLength += snprintf(logBuf + logBufLength, kLogBufMaxLength - logBufLength, " SD(%.2f)", fmodf(speed, 1000.0));
  strncat(logBuf + logBufLength, " ]", kLogBufMaxLength - logBufLength);
SS2K_LOG("BLE_Server", "%s", logBuf);

Shortened to:

SS2K_LOG("BLE_Server", " %s -> %s | %s | FTMS(IBD)[ HR(%d) CD(%.2f) PW(%d) SD(%.2f) ]", ss2k_log_hex_to_buffer(ftmsIndoorBikeData), hr % 1000, fmodf(cadRaw, 1000.0), watts % 10000, fmodf(speed, 1000.0));

Please let me know where I can help, but this one is a pretty complex problem (for me).

kadaan added a commit to kadaan/SmartSpin2k that referenced this pull request May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants