Skip to content

[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

Closed
wants to merge 25 commits into from
Closed

[CM-123] VerneMQ integration #7

wants to merge 25 commits into from

Conversation

AlbyIanna
Copy link

No description provided.

@sandeepmistry
Copy link
Contributor

@AlbyIanna can you please rebase this?

@@ -0,0 +1,43 @@
/*
Copy link
Contributor

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?

@@ -52,35 +52,137 @@ int ArduinoCloudClass::begin(Client& net)
return 0;
}

Serial.println("Compressed cert = ");
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delay(7000)?

Copy link
Author

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?

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

It makes sense. Thanks!

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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.
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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().

String _id;
ArduinoCloudThing Thing;
BearSSLClient* _bearSslClient;
HttpClient* _otaClient;
Copy link
Contributor

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.

Copy link
Contributor

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

String _stdoutTopic;
String _dataTopicIn;
String _dataTopicOut;
String _otaTopic;
Copy link
Contributor

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__)
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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.


#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) {
Copy link
Contributor

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.

Copy link
Contributor

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?

@sandeepmistry
Copy link
Contributor

@AlbyIanna can you please rebase this on master?

// MQTT topics definition
_stdoutTopic = "/a/d/" + _id + "/s/o";
_stdinTopic = "/a/d/" + _id + "/s/i";
_dataTopicIn = "/a/d/" + _id + "/e/i";
Copy link
Contributor

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.

@sandeepmistry
Copy link
Contributor

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.

@facchinm facchinm mentioned this pull request Aug 31, 2018
@facchinm
Copy link
Contributor

Closing after merging #8

@facchinm facchinm closed this Aug 31, 2018
@aentinger aentinger deleted the vernemq branch March 19, 2019 10:15
@aentinger aentinger restored the vernemq branch March 19, 2019 10:15
@aentinger aentinger deleted the vernemq branch March 19, 2019 10:15
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.

5 participants