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

[Electron/Photon/P1] Increase Device OS API argument lengths #1537

Merged
merged 3 commits into from
May 4, 2018

Conversation

technobly
Copy link
Member

@technobly technobly commented May 4, 2018

Problem

Device OS API arguments have limitations that can be increased.

Solution

API Field Prior to 0.8.0 Since 0.8.0 Comment
Variable Key 12 64
Variable Data 622 622
Function Key 12 64
Function Argument 63 622
Publish/Subscribe Event Name 64 64
Publish/Subscribe Event Data 255 622 Cloud API currently still limits to 255, but Device OS can publish 622. Will change Cloud API to accept 622. Done.
Number of registered Functions or Variables limited by memory available limited by memory available

An additional feature has been added that will return false when attempting to register a Particle.variable() or Particle.function() that exceeds the memory limits of the describe message (about 800 bytes for the Photon/P1/Electron). This message is a JSON object that describes or lists the "keys" needed. When an error occurs, that Variable or Function will be removed from the list available.

Steps to Test

Included test app.

Example App

#include "Particle.h"

#define PUB_70 "123456789012345678901234567890123456789012345678901234567890ABCDEFGHIJ"
#define SUB_70 "123456789012345678901234567890123456789012345678901234567890ABCDEFGHIJ"
#define VAR_70 "123456789012345678901234567890123456789012345678901234567890ABCDEFGHIJ"
#define VAR_64 "123456789012345678901234567890123456789012345678901234567890ABCD"
#define VAR_63 "123456789012345678901234567890123456789012345678901234567890ABC"
#define VAR_62 "123456789012345678901234567890123456789012345678901234567890AB"
#define VAR_61 "123456789012345678901234567890123456789012345678901234567890A"
#define VAR_60 "123456789012345678901234567890123456789012345678901234567890"
#define VAR_13 "1234567890123"
#define VAR_12 "123456789012"
#define VAR_OVF "12345678901234567890123456789012345678901234567890"

#define FUN_70 "123456789012345678901234567890123456789012345678901234567890ABCDEFGHIJ"
#define FUN_64 "123456789012345678901234567890123456789012345678901234567890ABCD"
#define FUN_63 "123456789012345678901234567890123456789012345678901234567890ABC"
#define FUN_62 "123456789012345678901234567890123456789012345678901234567890AB"
#define FUN_61 "123456789012345678901234567890123456789012345678901234567890A"
#define FUN_60 "123456789012345678901234567890123456789012345678901234567890"
#define FUN_13 "1234567890123"
#define FUN_12 "123456789012"

#define CHAR_700 "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ"
#define CHAR_622 "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890AB"

String my_variable_ovf = CHAR_622;
String my_variable_12 = CHAR_622;
String my_variable_13 = CHAR_622;
String my_variable_60 = CHAR_622;
String my_variable_61 = CHAR_622;
String my_variable_62 = CHAR_622;
String my_variable_63 = CHAR_622;
String my_variable_64 = CHAR_622;
String my_variable_70 = CHAR_700;

Serial1LogHandler logHandler(115200, LOG_LEVEL_ALL);

void handler(const char *event, const char *data)
{
    String my_event(event);
    String my_data(data);
    Serial.printlnf("Event Length: %d, Data Length: %d", my_event.length(), my_data.length() );
    Serial.printlnf("Event Name: %s, Event Data: %s", my_event.c_str(), my_data.c_str() );
}

void printInfo(String& string) {
    Serial.printlnf("Function Argument Length: %d", string.length() );
    Serial.printlnf("Function Argument: %s", string.c_str() );
}
int my_function_70(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_64(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_63(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_62(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_61(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_60(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_50(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_13(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_12(String arg) {
    printInfo(arg);
    return 0;
}
int my_function_ovf(String arg) {
    printInfo(arg);
    return 0;
}

void setup() {
    Serial.begin();

    // Particle.function(FUN_70, my_function_70); // error on compile (error shows 64 limit)
    Particle.function(FUN_12, my_function_12); // can receive 622 bytes as an argument
    Particle.function(FUN_13, my_function_13); // can receive 622 bytes as an argument
    Particle.function(FUN_60, my_function_60); // can receive 622 bytes as an argument
    Particle.function(FUN_61, my_function_61); // can receive 622 bytes as an argument
    Particle.function(FUN_62, my_function_62); // can receive 622 bytes as an argument
    Particle.function(FUN_63, my_function_63); // can receive 622 bytes as an argument
    Particle.function(FUN_64, my_function_64); // can receive 622 bytes as an argument

    // Particle.variable(VAR_70, &my_variable_70, STRING); // error on compile (error shows 64 limit)
    Particle.variable(VAR_12, &my_variable_12, STRING); // returns CHAR_622
    Particle.variable(VAR_13, &my_variable_13, STRING); // returns CHAR_622
    Particle.variable(VAR_60, &my_variable_60, STRING); // returns CHAR_622
    Particle.variable(VAR_61, &my_variable_61, STRING); // returns CHAR_622
    Particle.variable(VAR_62, &my_variable_62, STRING); // returns CHAR_622
    Particle.variable(VAR_63, &my_variable_63, STRING); // returns CHAR_622
    Particle.variable(VAR_64, &my_variable_64, STRING); // returns CHAR_622
    // Particle.variable(VAR_OVF, &my_variable_ovf, STRING); // add to increase describe message over the limit

    Particle.subscribe(SUB_70, handler, MY_DEVICES); // event 64 and data 255 (limited by Cloud API)
    waitUntil(Particle.connected);

    Particle.publish(PUB_70, CHAR_700, PRIVATE, WITH_ACK); // event 64 and data 622
}

void loop() {

}

References

Closes #1467


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

@technobly technobly added this to the 0.8.0-rc.4 milestone May 4, 2018
@technobly technobly requested a review from m-mcgowan May 4, 2018 00:02
@jme783
Copy link

jme783 commented May 4, 2018

This is great @technobly — I especially appreciate the well-documented P/R.

Just to confirm, what happens (for example) when you try and register a function with a name above the limit? Will that throw a compile error, or simply just not appear on your function list? Same with variable? What about an event data that exceeds the limit?

@technobly
Copy link
Member Author

@jme783 Currently that will throw a compile time error for keys over 12, but will throw errors with keys over 64 with the increased limits. The arguments lengths are not checked at compile time since they are typically not statically assertable, but they will truncate to the limits listed above.

@jme783
Copy link

jme783 commented May 4, 2018

Gotcha makes sense. So I imagine there will need to be a complimentary change in the Device Cloud to raise those limits when checking at compile time?

Copy link
Contributor

@m-mcgowan m-mcgowan left a comment

Choose a reason for hiding this comment

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

I will approve since structurally it looks fine and a good approach, but I had difficulty seeing some of the changes in the large blocks of code due to whitespace changes.

@technobly
Copy link
Member Author

@m-mcgowan you can tack on ?w=1 to the url to cleanup the white space changes. I had to do this myself and also git diff HEAD~3 -w locally works to review changes.

@technobly technobly merged commit 612ee42 into develop May 4, 2018
@technobly technobly deleted the feature/increase-limits branch May 4, 2018 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REQ: Particle Function Argument length increase from 63 to Max Available
3 participants