Conversation
WIP
|
Moving this provision to a different class.
Current functions getting affectedNew class |
Discussion points
|
possible stored data types
Organizing into categories
Summary
Conclusions
Next steps
|
produceconsumerobot
left a comment
There was a problem hiding this comment.
@nitin710 code review complete
| { | ||
| char input; | ||
| input = Serial.read(); | ||
| if (input == 'R') |
There was a problem hiding this comment.
What's the reasoning for moving restartMcu() out of the first serial.available() block?
As I recall this was added to enable enterprise wifi compatibility. Are we sure moving it still covers that purpose?
There was a problem hiding this comment.
I moved it to consolidate serial inputs to one location.
This shouldn't affect the enterprise wifi, because the reset option is still above the sensor setup and WiFi setup. But, I did not test it.
There was a problem hiding this comment.
Thinking more about, there is no reason we have a reset option downstream in the code.
If I weigh the pros and cons of having promts together in code, vs possibly breaking enterprise, preserving enterprise makes more sense.
So, I will add it back to this place. Will add a comment on why its there.
EmotiBit.cpp
Outdated
| if (Serial.available() >= 0) | ||
| { | ||
| char c = Serial.read(); | ||
| if (c == 'C') |
There was a problem hiding this comment.
It seems like we need 'C' (and perhaps the other serial inputs) to be defined as e.g. Inputs::CREDS in EmotiBitSerial.h so that we don't have magic chars littering the code
There was a problem hiding this comment.
Fixed. I liked your namespace.
SO changed letters to EmotiBitSerial::Input::CRED_UPDATE
EmotiBit.cpp
Outdated
| timeSinceLastPrint = millis(); | ||
| if (configFileError) | ||
| { | ||
| Serial.println("Press \"C\" to add/update cofig file."); |
There was a problem hiding this comment.
Serial.prints should probably also refer to EmotiBitSerial Inputs::CREDS or similar to avoid magic chars lying around
| Serial.println("{\"WifiCredentials\": [{\"ssid\":\"SSSS\",\"password\" : \"PPPP\"}]}"); | ||
| // ToDo: verify if we need a separate case for FACTORY_TEST. We should always have a config file, since FACTORY TEST is a controlled environment | ||
| setupFailed("Config file not found"); | ||
| if(loadConfig) |
There was a problem hiding this comment.
Is there a reason that this loadConfig block doesn't live inside EmotibitConfigManager?
There was a problem hiding this comment.
Moved it to ConfigManager. Created a bit of a hassle, but its done!
EmotiBitConfigManager.cpp
Outdated
| @@ -0,0 +1,287 @@ | |||
| #include <EmotiBitConfigManager.h> | |||
|
|
|||
| bool EmotiBitConfigManager::init(uint8_t sdCsPin) | |||
There was a problem hiding this comment.
I'm confused why we have/need to have SD.begin() inside EmotiBitConfigManager. It seems like makes it more spaghetti-like and less clear who's in charge of calling SD.begin and thus makes it more likely it getting called multiple times, which I'm not 100% sure what the behavior would be. Can we simply require sdInit() to be called within EmotiBit.cpp prior to calling updateWiFiCredentials?
There was a problem hiding this comment.
Fixed. As discussed, EmotiBIt now inits SD and passes pointer to ConfigManager class
| file = SD.open(configFilename); | ||
| parseError = deserializeJson(configAsJson, file); | ||
| file.close(); | ||
| } |
There was a problem hiding this comment.
It seems like perhaps the code logic could be simplified if(!fileExists || parseError) was handled here by creating new file with zero creds?
There was a problem hiding this comment.
Fixed the logic. Yes, i bubbled if(!fileExists || parseError) logic upstream. i think it's more readable now
EmotiBitConfigManager.cpp
Outdated
| configAsJson["WifiCredentials"].remove(deleteIndex); | ||
| SD.remove(configFilename); | ||
| #if defined ARDUINO_FEATHER_ESP32 | ||
| file = SD.open(configFilename, FILE_WRITE); |
There was a problem hiding this comment.
It seems like this SD.open + serialJsonPretty is a copy/paste of code above with poorer error handling. Perhaps it should be pulled out int a function?
There was a problem hiding this comment.
Yes, created a new function to handle file creation from JsonElement
EmotiBitConfigManager.cpp
Outdated
| } | ||
| else | ||
| { | ||
| // send list of existing credentials |
There was a problem hiding this comment.
This comment seems out of place/perhaps vestigial.
There was a problem hiding this comment.
Outdated comment. removing.
produceconsumerobot
left a comment
There was a problem hiding this comment.
@nitin710 testing review complete
EmotiBitConfigManager.cpp
Outdated
| EmotiBitSerial::sendMessage(EmotiBitFactoryTest::TypeTag::FIRMWARE_VERSION, emotibitFwVersion); | ||
| // instructions | ||
| Serial.println("Options available:"); | ||
| Serial.println("1. Add a wifi credential. Usage: @WA,{\"ssid\":\"SSSS\",\"password\" : \"PPPP\"}~"); |
There was a problem hiding this comment.
I think perhaps it could be clearer to format the instructions as:
- Add a wifi credential -- Send: @Wa,{"ssid":"SSSS","password" : "PPPP"}~
EmotiBitConfigManager.cpp
Outdated
| if(configAsJson["WifiCredentials"].size()) | ||
| { | ||
| Serial.println("##################################"); | ||
| Serial.println("config file credetials:"); |
There was a problem hiding this comment.
Add n to credetials
There was a problem hiding this comment.
Capital c in Config
EmotiBitConfigManager.cpp
Outdated
| } | ||
| else | ||
| { | ||
| Serial.println("not a valid serial message. Expecting @TYPETAG,PAYLOAD~"); |
There was a problem hiding this comment.
Capital N in not
There was a problem hiding this comment.
Add a : to Expecting: @TYPETAG,PAYLOAD~
| // Send EmotiBit Firmware version to host | ||
| EmotiBitSerial::sendMessage(EmotiBitFactoryTest::TypeTag::FIRMWARE_VERSION, emotibitFwVersion); | ||
| // instructions | ||
| Serial.println("Options available:"); |
There was a problem hiding this comment.
Should the Options available be printed after every command so that you don't have to scroll back up to see the options?
There was a problem hiding this comment.
I played with it, i personally didn't like it. Too much going on the screen.
|
@produceconsumerobot made the requested changes. Ready for review. (long list of changes.) |
produceconsumerobot
left a comment
There was a problem hiding this comment.
It would probably be good if I test it one more time if you want to drop a bin file in the PR, but code looks much nicer.
| #ifdef ARDUINO_FEATHER_ESP32 | ||
| bool EmotiBitConfigManager::init(fs::SDFS* sd) | ||
| { | ||
| SD = sd; |
There was a problem hiding this comment.
I might have chosen a variable name that doesn't overload SD to avoid confusion, but I don't think it matters much.
There was a problem hiding this comment.
Leaving it as it is.
| EmotiBitSerial::sendMessage(EmotiBitFactoryTest::TypeTag::FIRMWARE_VERSION, emotibitFwVersion); | ||
| // instructions | ||
| Serial.println("Options available:"); | ||
| Serial.println("1. Add a wifi credential. Send: @WA,{\"ssid\":\"SSSS\",\"password\" : \"PPPP\"}~"); |
There was a problem hiding this comment.
Come to think of it, we could probably use variables here instead of magic hard coded @ls~ etc, but it's not a huge deal since we're probably loathe to change these.
Description
Requirements
Issues Referenced
Documentation update
Notes for Reviewer
SD Card Serial Add Wifi Credentials API Diagramdrawing in drive.Testing
Results
Feature Tests
Steps to test
@WA,{"ssid":"ssid_name","password" : "network_password"}~@WD,<number>~@LS,~Shared files
1.9.0.feat-sdCardWiFiCredentials.16.zipChecklist to allow merge
masterDIGITAL_WRITE_DEBUG= false (if set true while testing)