forked from knolleary/pubsubclient
-
Notifications
You must be signed in to change notification settings - Fork 4
(WIP) Feature: Implement fstring topics #72
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
Open
hmueller01
wants to merge
30
commits into
master
Choose a base branch
from
implement-fstring-topics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e569a74
add defines for needed PROGMEM functions
1a6d44b
implemented writeString(const __FlashStringHelper* ...), writeString_P()
d2fa270
Merge branch 'master' into implement-fstring-topics
07efb35
Merge branch 'master' into implement-fstring-topics
hmueller01 64709f1
fix merge failure
hmueller01 b2fb86c
added writeString(const __FlashStringHelper* ...), writeString_P()
hmueller01 c461807
added __FlashStringHelper
hmueller01 ff1997e
Merge branch 'master' into implement-fstring-topics
hmueller01 5019584
Merge branch 'master' into implement-fstring-topics
hmueller01 79bd37d
Merge branch 'master' into implement-fstring-topics
hmueller01 f8374e8
Merge branch 'master' into implement-fstring-topics
hmueller01 07ebf85
do not use prog_uint8_t, deprecated
hmueller01 42d278f
Merge branch 'master' into implement-fstring-topics
hmueller01 92ce07f
Merge branch 'master' into implement-fstring-topics
hmueller01 3de4409
removed writeString(__FlashStringHelper*), added beginPublishImpl(), …
hmueller01 2df1cf2
added F() macro
hmueller01 30d9095
Merge branch 'master' into implement-fstring-topics
hmueller01 1aec205
implemented writeStringImpl() using template, added __FlashStringHelp…
hmueller01 3ba5637
fixed wrong return type of writeStringImpl()
hmueller01 1fdd6dc
shorten source code size for getting string length
hmueller01 541876a
removed template implementation by classic parameter
hmueller01 ee3b134
Merge branch 'master' into implement-fstring-topics
hmueller01 2d7b1b2
added publish(__FlashStringHelper* topic, __FlashStringHelper* payloa…
hmueller01 2fe356c
make all only beginPublishImpl / writeStringImpl calling functions in…
hmueller01 02f55f9
fix compiler error: moved public inline functions to header file
hmueller01 ae7cd3e
fix compiler error: moved public inline functions to header file
hmueller01 5ea9b74
implement write_P(PGM_P string)
hmueller01 443097d
Initial revision
hmueller01 1a3b765
fix arduino-cli compile error
hmueller01 b7fe4c3
implemented bool subscribeImpl(bool progmem, ...) and bool unsubscrib…
hmueller01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // Example sketch showing how to use PubSubClient with strings stored in PROGMEM. | ||
| // This needs to be an empty file to satisfy the arduino-cli build system. | ||
| // See src/mqtt_progmem.cpp for the actual example code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ; PlatformIO Project Configuration File | ||
| ; | ||
| ; Build options: build flags, source filter | ||
| ; Upload options: custom upload port, speed and extra flags | ||
| ; Library options: dependencies, extra library storages | ||
| ; Advanced options: extra scripting | ||
| ; | ||
| ; Please visit documentation for the other options and examples | ||
| ; https://docs.platformio.org/page/projectconf.html | ||
| ; https://docs.platformio.org/en/latest/boards/atmelavr/uno.html | ||
|
|
||
| [platformio] | ||
| description = Basic MQTT example with Authentication and Progmem strings | ||
|
|
||
| [env] | ||
| framework = arduino | ||
| lib_deps = | ||
| arduino-libraries/Ethernet @ ^2.0.2 | ||
| ; hmueller01/PubSubClient3 @ ^3.2.1 | ||
| https://github.com/hmueller01/pubsubclient3.git#implement-fstring-topics | ||
| build_flags = | ||
| ; -D DEBUG_ESP_PORT=Serial | ||
| ; -D DEBUG_PUBSUBCLIENT | ||
| ; -D MQTT_MAX_PACKET_SIZE=512 | ||
| ; -D MQTT_KEEPALIVE=120 | ||
|
|
||
| [env:uno] | ||
| platform = atmelavr | ||
| board = uno | ||
|
|
||
| [env:esp8266] | ||
| platform = espressif8266 | ||
| platform_packages = platformio/framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git | ||
| board = esp12e | ||
| build_flags = | ||
| ${env.build_flags} | ||
| -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305 | ||
|
|
||
| [env:esp32] | ||
| platform = espressif32 | ||
| board = esp32dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| Basic MQTT example with Authentication | ||
|
|
||
| - connects to an MQTT server, providing username | ||
| and password | ||
| - publishes "hello world" to the topic "outTopic" | ||
| - subscribes to the topic "inTopic" | ||
| */ | ||
|
|
||
| #include <Ethernet.h> | ||
| #include <PubSubClient.h> | ||
| #include <SPI.h> | ||
|
|
||
| // Update these with values suitable for your network. | ||
| byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED}; | ||
| IPAddress ip(172, 16, 0, 100); | ||
| IPAddress server(172, 16, 0, 2); | ||
| const char HELLO_WORLD_3[] PROGMEM = "hello world 3"; | ||
| const char HELLO_WORLD_4[] PROGMEM = "hello world 4"; | ||
|
|
||
| void callback(char* topic, uint8_t* payload, size_t plength) { | ||
| // handle message arrived | ||
| } | ||
|
|
||
| EthernetClient ethClient; | ||
| PubSubClient client(server, 1883, callback, ethClient); | ||
|
|
||
| void setup() { | ||
| Ethernet.begin(mac, ip); | ||
| // Note - the default maximum packet size is 128 bytes. If the | ||
| // combined length of clientId, username and password exceed this use the | ||
| // following to increase the buffer size: | ||
| // client.setBufferSize(255); | ||
|
|
||
| if (client.connect("arduinoClient", "testuser", "testpass")) { | ||
| client.publish(F("outTopic"), "hello world 1", MQTT_QOS0, false); | ||
| client.publish(F("outTopic"), F("hello world 2"), MQTT_QOS1, false); | ||
| client.publish_P(F("outTopic"), HELLO_WORLD_3, MQTT_QOS2, false); | ||
| client.beginPublish(F("outTopic"), strlen_P(HELLO_WORLD_4), MQTT_QOS1, false); | ||
| client.write_P(HELLO_WORLD_4); | ||
| client.endPublish(); | ||
| client.subscribe("inTopic"); | ||
| } | ||
| } | ||
|
|
||
| void loop() { | ||
| client.loop(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is a number of
strnlen(and _P) checks, which are all against either max. Packet size or buffer size.However in a packet/buffer, there is also the topic and some header, so those checks are still allowing for some overflow.
The max. possible packet size is probably not really a problem as we won't get that large payloads, or at least not from a char pointer.
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.
As far as I understand the max. length is only there to limit strlen somewhere if the payload is corrupted. Or who wants to send ~268MB payload on a micro controller?
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'm not sure if we really need
strnlen_P()or if we just could usestrlen_P()and let thebuild_header()do the check work ...