The documentation for this library is quite terse. I can’t seem to figure out the syntax for publishing data with the persistent bit set? Anyone have this info? I can’t find any information on it in the GitHub repo.
Have you filed an issue on the GitHubrepo?
You can/should also tag the person yoz want to ask specific questions - in this case @hirotakaster
Sorry quite terse document, but I think README is fully satisfied for.
And “persistent bit” is what? QoS or session data?
Sorry, I meant retained. So in my sketch do I put client.publish(topic, payload, retained=true)?
Do I just have to modify the callback function so that when I execute a client.publish command in the loop it will just toggle the retained bit? If you had an example sketch it would really help to see it in action. You have examples for qos but nothing with how to set the retained bit.
So I have this in my sketch:
String PRessure = String(inches);
String INTempF = String(inTempF);
String INHumidity = String(inHumidity);
unsigned int PR_len = PRessure.length();
unsigned int INT_len = INTempF.length();
unsigned int INH_len = INHumidity.length();
client.publish("weather/inTemp",INTempF,INT_len,true);
client.publish("weather/pressure",PRessure);
client.publish("weather/inHumidity",INHumidity);
and I have the callback function set like this:
void callback(char* topic, byte* payload, unsigned int length, bool retain);
byte server[] = { 192,168,250,57 };
MQTT client(server, 1883, callback);
The compiler spits out this error:
Processing rfm69gateway.ino
Checking library RFM69-Particle...
Checking library MQTT...
Checking library Adafruit_BME280...
Installing library RFM69-Particle 0.0.2 to lib/RFM69-Particle ...
Installing library Adafruit_BME280 1.1.4 to lib/Adafruit_BME280 ...
Installing library MQTT 0.4.22 to lib/MQTT ...
Library Adafruit_BME280 1.1.4 installed.
Library MQTT 0.4.22 installed.
Library RFM69-Particle 0.0.2 installed.
make -C ../modules/photon/user-part all
make[1]: Entering directory '/firmware/modules/photon/user-part'
make -C ../../../user
make[2]: Entering directory '/firmware/user'
Building cpp file: src/rfm69gateway.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-8-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=8 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD008 -DUSBD_PID_CDC=0xC008 -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=8 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.6.2 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -Isrc -I./libraries -Isrc -Isrc -Isrc -Isrc -Ilib/RFM69-Particle/src -Ilib/MQTT/src -Ilib/Adafruit_BME280/src -I. -MD -MP -MF ../build/target/user/platform-8-msrc/rfm69gateway.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=BCM9WCDUSI14 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSE_THREADING=0 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_THREADING=0 -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=4 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,108 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\"" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-8-msrc/rfm69gateway.o src/rfm69gateway.cpp
rfm69gateway.ino: In function 'void callback(char*, byte*, unsigned int)':
rfm69gateway.ino:136:15: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
rfm69gateway.ino: In function 'void loop()':
rfm69gateway.ino:307:57: error: call of overloaded 'publish(const char [15], String&, unsigned int&, bool)' is ambiguous
rfm69gateway.ino:307:57: note: candidates are:
In file included from rfm69gateway.ino:5:0:
lib/MQTT/src/MQTT.h:160:10: note: bool MQTT::publish(const char*, const char*, MQTT::EMQTT_QOS, bool, uint16_t*) <near match>
bool publish(const char *topic, const char* payload, EMQTT_QOS qos, bool dup, uint16_t *messageid = NULL);
^
lib/MQTT/src/MQTT.h:160:10: note: no known conversion for argument 3 from 'unsigned int' to 'MQTT::EMQTT_QOS'
lib/MQTT/src/MQTT.h:164:10: note: bool MQTT::publish(const char*, const uint8_t*, unsigned int, bool) <near match>
bool publish(const char *topic, const uint8_t *payload, unsigned int plength, bool retain);
^
lib/MQTT/src/MQTT.h:164:10: note: no known conversion for argument 2 from 'String' to 'const uint8_t* {aka const unsigned char*}'
rfm69gateway.ino:304:18: warning: unused variable 'PR_len' [-Wunused-variable]
rfm69gateway.ino:306:18: warning: unused variable 'INH_len' [-Wunused-variable]
../build/module.mk:267: recipe for target '../build/target/user/platform-8-msrc/rfm69gateway.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-8-msrc/rfm69gateway.o] Error 1
../../../build/recurse.mk:11: recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [user] Error 2
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2
Any ideas what I’m doing wrong here?