Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Publishing > 180 characters with nodemcu
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Publishing > 180 characters with nodemcu

by Sithman on Sat Mar 28, 2020 2:49 am

Dear all,

I'm dealing with the problem of SW reset of my NodeMCU when the string published to feed is longer then 180 char.

Does anybody now, what can be wrong? Are there some limitations of the publish method?

Please see the code below with testing string 190 chars:

Code: Select all | TOGGLE FULL SIZE
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
// WiFi parameters
#define WLAN_SSID "removed"                    // Insert here your WiFi network name
#define WLAN_PASS "removed"                    // Insert here the password for your WiFi network
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME  "removed"
#define AIO_KEY       "romeved"

char *test = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";

// Functions declarations
void connect();
WiFiClient client;

// MQTT definitions
const char MQTT_SERVER[] = AIO_SERVER;
const char MQTT_CLIENTID[] = AIO_KEY __DATE__ __TIME__;
const char MQTT_USERNAME[] = AIO_USERNAME;
const char MQTT_PASSWORD[] = AIO_KEY;

// Adafruit IO client definitions
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);

// Adafruit IO Feeds definition
const char CAMERA1[] = AIO_USERNAME "/feeds/camera1";

Adafruit_MQTT_Publish camera1 = Adafruit_MQTT_Publish(&mqtt, CAMERA1);

void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.println();

  // Connect to WiFi
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);
  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    delay(10);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Connect to MQTT and Adafruit IO
  connect();
}

void loop() {
  // ping Adafruit IO a few times to make sure we remain connected
  if (!mqtt.ping(3)) {
    if (!mqtt.connected()) connect();     // reconnect to adafruit io
  }

  // Publish data to the relevant feeds of Adafruit IO
  if (!camera1.publish(test)) {
    Serial.println("Failed to publish data");
  }
  else {
    Serial.print("Data published");
  }
  delay(1000);
}

/**
 * This method connects to the Adafruit IO and MQTT
 **/
void connect() {
  Serial.print("Connecting to Adafruit IO... ");
  int8_t ret;
  while ((ret = mqtt.connect()) != 0) {
    switch (ret) {
      case 1: Serial.println("Wrong protocol"); break;
      case 2: Serial.println("ID rejected"); break;
      case 3: Serial.println("Server unavail"); break;
      case 4: Serial.println("Bad user/pass"); break;
      case 5: Serial.println("Not authed"); break;
      case 6: Serial.println("Failed to subscribe"); break;
      default: Serial.println("Connection failed"); break;
    }
    if (ret >= 0) {
      mqtt.disconnect();
    }
    Serial.println("Retrying connection...");
    delay(5000);
  }
  Serial.println("Adafruit IO Connected!");
}




Console output:
........
WiFi connected
IP address:
192.168.0.107
Connecting to Adafruit IO... Adafruit IO Connected!

Exception (28):
epc1=0x40205561 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000034 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffd90 end: 3fffffc0 offset: 01a0
3fffff30:  3ffe8728 3ffe87e7 00000002 000001f4 
3fffff40:  0000000d 3ffee564 3ffee586 3ffee728 
3fffff50:  00000000 3ffee586 3ffee564 40202bf8 
3fffff60:  3fffdad0 3ffee564 00000000 40202c78 
3fffff70:  3ffe87e7 3ffe8728 0100a8c0 3ffee728 
3fffff80:  3ffe86a8 00000000 3ffee564 40202dd6 
3fffff90:  3fffdad0 00000000 3ffee564 40201243 
3fffffa0:  3fffdad0 00000000 3ffee6e8 402039e4 
3fffffb0:  feefeffe feefeffe 3ffe84ec 40100b95 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld


Thanks in advance for some answer.

Best regards, Mike
Last edited by brubell on Tue Mar 31, 2020 11:53 am, edited 1 time in total.
Reason: added [code], fixed title

Sithman
 
Posts: 3
Joined: Thu Mar 12, 2020 11:49 am

Re: Publishing > 180 characters with nodemcu

by brubell on Tue Mar 31, 2020 11:59 am

Hi Mike,

This limitation is not with the publish method or Adafruit IO, it's with the Adafruit MQTT client library used by Adafruit IO Arduino.

The largest packet buffer we're able to send is ~90 chars (https://github.com/adafruit/Adafruit_MQ ... MQTT.h#L98)
Code: Select all | TOGGLE FULL SIZE
// Largest full packet we're able to send.
// Need to be able to store at least ~90 chars for a connect packet with full
// 23 char client ID.
#define MAXBUFFERSIZE (150)


You could try either increasing this buffer size, or send multiple (smaller) strings to Adafruit IO

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Publishing > 180 characters with nodemcu

by Sithman on Wed Apr 01, 2020 12:59 am

Dear Brubell,

thank you very much for information. It works. For text messages is ok.
Now arose new question.
When I try to send base64 data to same feed. Publish from CPU works good, but the data received to feed are destructed:

Sent:

char *test = "/9j/4AAQSkZJRgABAQEAYABgAAD/4QD6RXhpZgAATU0AKgAAAAgABwEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAQAAAAcgE7AAIAAAAFAAAAgodpAAQAAAABAAAAiJydAAEAAAAKAAAA6AAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMi41AE1pa2UAAAAEkAMAAgAAABQAAAC+kAQAAgAAABQAAADSkpEAAgAAAAM3NQAAkpIAAgAAAAM3NQAAAAAAADIwMjA6MDM6MTkgMTk6MjM6MTQAMjAyMDowMzoxOSAxOToyMzoxNAAAAE0AaQBrAGUAAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgIC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1a6Jeh5dTC5nQqyhQzulRhdtU+SL5E22o3cW7q9tW/U9S/wCCu3xA1H4OftNfDH4i/Hz4M2utNrnwtks5vBmmXkVnbHWHuJbe4QyqZNkCzIQCu5mVV+ZWYuvzCPj78G/HH7L3h74f+JUutD8ReDfi4LvVL6ztWmhOjmOLfGEH3pUl83ZtYAqG3EEqT2cMcO11kOCr0Zc0Y25YaKyUqi5r7NvnXu9OVa66ePLiKnDE18E5JRtb2rTk5JQUmrW5lpBWbWrd7bnp/wAPP+C4HxU/Ye1TxZ8GPg14ZTUPBk3i+71Pwj9okNuYdPmWMRDyjv8ALLbDKybjh5nGT1ororeEODzSf1t4uonNJtba2V3o7Xbu35n53nXFtPD5viKVfDR5lOSdtUtXZJ6XSVktE7bo/9k=";

//received to Adafruit IO feed /9j/4AAQSkZJRgABAQEAYABgAAD/4QD6RXhpZgAATU0AKgAAAAgABwEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAQAAAAcgE7AAIAAAAFAAAAgodpAAQAAAABAAAAiJydAAEAAAAKAAAA6AAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMi41AE1pa2UAAAAE0�Sithman/feeds/camera1/9j/4AAQSkZJRgABAQEAYABgAAD/4QD6RXhpZgAATU0AKgAAAAgABwEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAQAAAAcgE7AAIAAAAFAAAAgodpAAQAAAABAAAAiJydAAEAAAAKAAAA6AAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMi41AE1pa2UAAAAE0�Sithman/feeds/camera1/9j/4AAQSkZJRg

Is this right way how to proceed the picture data from CPU to adafruit dashboard?

Thanks in advance, Mike

Sithman
 
Posts: 3
Joined: Thu Mar 12, 2020 11:49 am

Re: Publishing > 180 characters with nodemcu

by brubell on Fri Apr 03, 2020 10:31 am

I tried to enter your B64 data into Adafruit IO web:
Code: Select all | TOGGLE FULL SIZE
/9j/4AAQSkZJRgABAQEAYABgAAD/4QD6RXhpZgAATU0AKgAAAAgABwEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAQAAAAcgE7AAIAAAAFAAAAg


and was met with the following error:
Code: Select all | TOGGLE FULL SIZE
MQTT ERROR: error saving data to brubell/feeds/, value cannot be larger than 1024 bytes (1 KB) when feed history is on. 1871 bytes received


You'll need to disable Feed History for the feed which you're sending the picture data to. When history is turned OFF, feed data is limited to 100KB (102400 bytes) in size.

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Re: Publishing > 180 characters with nodemcu

by Sithman on Fri Apr 03, 2020 3:19 pm

Dear Brubell,

I checked, changed the buffer in library Adafruit_MQTT.h to #define MAXBUFFERSIZE (30000).
My feed history is right (OFF). I made more tests and the problem start when the string is longer then 225 chars.
Until 225 chars reached the data are sent right. More then 225 char cuts the string and adds at the end of string "�Sithman/feeds/camera".
There is some overloading on IO feed.

Br, Mike.

Sithman
 
Posts: 3
Joined: Thu Mar 12, 2020 11:49 am

Re: Publishing > 180 characters with nodemcu

by regenerativa on Thu Aug 27, 2020 8:18 pm

Hi Sithman,

Have you figured it out? I'm dealing with the same issue.

regenerativa
 
Posts: 3
Joined: Tue Aug 25, 2020 3:45 pm

Re: Publishing > 180 characters with nodemcu

by brubell on Fri Aug 28, 2020 10:12 am

Sithman wrote:Dear Brubell,

I checked, changed the buffer in library Adafruit_MQTT.h to #define MAXBUFFERSIZE (30000).
My feed history is right (OFF). I made more tests and the problem start when the string is longer then 225 chars.
Until 225 chars reached the data are sent right. More then 225 char cuts the string and adds at the end of string "�Sithman/feeds/camera".
There is some overloading on IO feed.

Br, Mike.

Could you add to the thread the data the feed should show?

brubell
 
Posts: 1043
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.