-
Notifications
You must be signed in to change notification settings - Fork 80
[CM-123] VerneMQ integration #7
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
Conversation
@AlbyIanna can you please rebase this? |
src/SerialFlashStorage.h
Outdated
@@ -0,0 +1,43 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the flash storage?
src/ArduinoCloud.cpp
Outdated
@@ -52,35 +52,137 @@ int ArduinoCloudClass::begin(Client& net) | |||
return 0; | |||
} | |||
|
|||
Serial.println("Compressed cert = "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove printing the compressed cert to the serial
while (!Serial) { | ||
; // wait for serial port to connect. Needed for native USB port only | ||
} | ||
delay(7000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why delay(7000)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It because of the Serial. I want to make sure the sketch doesn't start if the serial isn't up, but at the same i want the sketch to work even when you are not using the serial. This is mainly because of the Getting Started: we are telling users that, once uploaded the sketch, they can unplug the board and plug it to a socket wall. Do you have a better idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best practice in this case is:
int timeout = millis() + TIMEOUT;
while (!Serial && (millis() < timeout)) {}
so it starts immediately when the serial port is connected and waits a bit if unplugged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should not happen in this case but to avoid wrapping errors better to do the delta between currtime and start time
unsigned long start = millis();
while (!Serial && (millis() - start < TIMEOUT)) {}
///////please enter your sensitive data in the Secret tab/arduino_secrets.h | ||
char ssid[] = SECRET_SSID; // your network SSID (name) | ||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) | ||
int status = WL_IDLE_STATUS; // the WiFi radio's status | ||
String serialString = ""; // the string used to compose network messages from the received characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a better name for this, maybe something like inputBuffer
or cloudSerialBuffer
?
} | ||
|
||
// Just to be able to simulate MKR1000's responses through the serial monitor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sketch can also run on the MKR WiFi 1010?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the MKR1010 would need WiFiNINA instead of WiFi101
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, maybe we can add a comment at the start of the sketch that says:
// change to WiFiNINA.h if you are using the MKR WiFi 1010 or MKR Vidor 4000
digitalWrite(6, LOW); | ||
} | ||
|
||
// Send back the command you just applied. This way the Angular frontend can stay synchronized with the MKR1000 state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the comment about Angular, most users won't know what it is.
// try establish the MQTT broker connection | ||
connect(); | ||
// delay eventually used for the nex re-connection try | ||
delay(timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems weird to have a delay in the lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no problem with the tight connect() loop I'd replace the condition as
timeout += millis();
while(!_mqttClient.connected() && (retries++ < maxRetries) && (millis() < timeout)) {...}
if (retries == maxRetries || millis() < timeout)
return false;
so it fails in both cases without locking for too long
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, this code has integer overflow problems. Please use only unsigned long
and subtractions when dealing with millis()
.
src/ArduinoCloudV2.h
Outdated
String _id; | ||
ArduinoCloudThing Thing; | ||
BearSSLClient* _bearSslClient; | ||
HttpClient* _otaClient; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see used OTA anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are 2 commits missing from this PR 02a1994 and 02a1994 that completely remove the OTA code while we find a better way to handle it 🙂
@AlbyIanna I'm pushing them to this branch
src/ArduinoCloudV2.h
Outdated
String _stdoutTopic; | ||
String _dataTopicIn; | ||
String _dataTopicOut; | ||
String _otaTopic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is not used.
// Clean up existing Mqtt connection, create a new one and initialize it | ||
void reconnect(Client& net); | ||
|
||
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're adding this, it would be good to use it in an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we should add at least an example using the properties @AlbyIanna
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, i'll work on the new example then.
Talking with @facchinm we agreed on using a property instead of the CloudSerial in the CloudBlink sketch, and eventually write another example sketch that uses the CloudSerial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need cloud serial for OOBE then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we have to use it. And sadly we cannot use the properties to make the led blink in the OOBE, because otherwise we'd also have to create a Thing and introduce the user to the Arduino Cloud application, which is totally outside the scope of the OOBE.
src/ArduinoCloudV2.h
Outdated
|
||
#define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__) | ||
|
||
template<typename T> void addPropertyReal(T& property, String name, permissionType _permission = READWRITE, long seconds = ON_CHANGE, T minDelta = 0, void(*fn)(void) = NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have addProperty
and addPropertyReal
both as public. It will strange from a documentation point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for a better way to do the variable name -> string property trick without using a macro but none was satisfying; theoretically addPropertyReal should be protected in Thing class and CloudV2 should be declared as friend, but this clashes with the macro stuff. Any better idea?
@AlbyIanna can you please rebase this on master? |
I really dislike that I had to expose the Thing object but otherwise the addProperty() call would become terrible. I added a line on Cloud_blink example to show the composition of functions on properties. It can be safely removed in the next iteration.
// MQTT topics definition | ||
_stdoutTopic = "/a/d/" + _id + "/s/o"; | ||
_stdinTopic = "/a/d/" + _id + "/s/i"; | ||
_dataTopicIn = "/a/d/" + _id + "/e/i"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to have a discussion on this topic structure. It makes things a bit complicated if one thing wants to listen to another things property.
Me and @facchinm discussed splitting what is needed for OOBE into a new PR. Then the cloud thing stuff can be merged into master once we have end to end functioning. |
Closing after merging #8 |
No description provided.