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

group save on Arduino UNO Wifi Rev2 with "Adafruit IO Arduin
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.

group save on Arduino UNO Wifi Rev2 with "Adafruit IO Arduin

by Geyoyo on Sun Dec 08, 2019 9:28 am

I made simple program by using article

https://www.woolseyworkshop.com/2019/06 ... ide-world/

It uses "Adafruit IO Arduino v3.2.3" and WiFiNINA library, and ARDUINO megaAVR boards v1.8.4.

Sending three temperature feeds was ok, but I have them not synchronized, they frequently have different times,
even after making saving one after another:

Code: Select all | TOGGLE FULL SIZE
 

void loop()
{

   aio.run();  // keep client connected to AIO service

  temp1feed -> save("NA");
  temp2feed -> save(tempfloat2);
  temp3feed -> save(tempfloat3);  //raw

  delay(60000);

}


Found in examples "group save".

Changed code to

Code: Select all | TOGGLE FULL SIZE
 

void loop()
{

   aio.run();  // keep client connected to AIO service


  Serial.println ("temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13");

  group -> set("temp1","NA"); //slidng
  group -> set("temp2",tempfloat2); //real
  group -> set("temp3",tempfloat3);  //raw

  group -> save();

  delay(60000);

}


And above freezes Arduino.

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13



Before making this problem examples it even restarted Arduino, program started from beginning.

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13?Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13?Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13


with group save commented out it is as this

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13



I added debuging lines

Code: Select all | TOGGLE FULL SIZE
 

void loop()
{


Serial.println("before aio.run");
  aio.run();  // keep client connected to AIO service
Serial.println("after aio.run"); 


  Serial.println ("temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13");

  group -> set("temp1","NA"); //slidng
  group -> set("temp2",tempfloat2); //real
  group -> set("temp3",tempfloat3);  //raw

Serial.println("before group save");
  group -> save();
Serial.println("after group save"); 

  delay(60000);

}


and Arduino Uno Wifi Rev2 stops on second "aio.run()", just after using "group -> save()"

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
before aio.run
after aio.run
temp3 = 23.56, temp 2 = 34.80, temp3 = 24,13
before group save
after group save
before aio.run




So I commented "aio.run()", it was working for 30 minuts but then feeds stopped working.

I wanted to try disconnect/connect, but there is no such function as "disconnect" available,
Anyway, the more important is that something is wrong with "group -> save()" or "aio.run()" on Arduino Uno Wifi Rev2.

Could anyone help me with keeping Adafruit IO connection and be able to continuously use "group -> save()"?

Actual full code with "aio.run()" commented out.

Code: Select all | TOGGLE FULL SIZE

//ARDUINO megaAVR boards v1.8.4
#include "SparkFunLSM6DS3.h"  //v1.0.0
#include "Wire.h"  //??
#include "SPI.h" //??

LSM6DS3 myIMU(SPI_MODE, SPIIMU_SS); //Default constructor is I2C, addr 0x6B


#include <OneWire.h>  //Jim Studt.... v2.3.5
#include <DallasTemperature.h>  //v3.8.0

OneWire oneWire( A3 ); //Podłączenie termometrow do A3, a3 sig + GND, 5V
DallasTemperature sensors( &oneWire ); //Przekazania informacji do biblioteki


//// Defines
#define AIO_USERNAME    "XXXXXXXXXXXXX"
#define AIO_KEY         "XXXXXXXXXXXXXXXXXXXXXXXXXX"
#define AIO_TEMP1       "temp1"
#define AIO_TEMP2       "temp2"
#define AIO_TEMP3       "temp3"
#define WIFI_SSID       "XXXXXXXXXXXXXXX"
#define WIFI_PASS       "XXXXXXXXXXXXXXXXXXXXXXXX"
#define USE_AIRLIFT     // required for Arduino Uno WiFi R2 board compatability

// Libraries
#include <AdafruitIO_WiFi.h> //v3.2.3

// Constructors
AdafruitIO_WiFi aio(AIO_USERNAME, AIO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, SPIWIFI_RESET, NINA_GPIO0, &SPI);
//AdafruitIO_Feed *temp1feed = aio.feed(AIO_TEMP1);
//AdafruitIO_Feed *temp2feed = aio.feed(AIO_TEMP2);
//AdafruitIO_Feed *temp3feed = aio.feed(AIO_TEMP3);
//AdafruitIO_Feed *temp4feed = aio.feed(AIO_TEMP4);
//AdafruitIO_Feed *temp5feed = aio.feed(AIO_TEMP5);

// set up the group
AdafruitIO_Group *group = aio.group("default");

float tempfloat1,tempfloat2, tempfloat3, tempfloat4, tempfloat5, oldzielony=25, oldczerwony=25;
#define SLIDING 10
#define GRACE 25  //tyle MINUT trzeba na ustabilizowanie Onboard termometer
int czekamy = 0 , pozycja = 0, i;
float temps[SLIDING], suma;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000); //relax...
  Serial.println("Processor came out of reset.\n");
 
  //Call .begin() to configure the IMU
  myIMU.begin();
 
  sensors.begin(); //Inicjalizacja czujnikow temperatury


     // Adafruit IO connection and configuration
   Serial.print("Connecting to Adafruit IO");
   aio.connect();  // connect to Adafruit IO service
   while(aio.status() < AIO_CONNECTED) {
      Serial.print(".");
      delay(1000);  // wait 1 second between checks
   }
   Serial.println();
   Serial.println(aio.statusText());  // print AIO connection status

   aio.run();
}


void loop()
{

  //aio.run();  // keep client connected to AIO service
 
  tempfloat3=myIMU.readTempC(); //raw
  temps[pozycja++] = tempfloat3;
  if ( pozycja > SLIDING -1 ) pozycja = 0; //krecimy sie po tablicy

  if ( czekamy <= GRACE )
          czekamy++ ; //po grace juz nie zmieniamy "czekamy"

  suma = 0 ;
  for ( i = 0; i < SLIDING ; i++) suma = suma + temps[i];
   
  tempfloat1 = suma / SLIDING; 


  sensors.requestTemperatures();
 
  tempfloat2=sensors.getTempCByIndex(0);
  if (tempfloat2<-30 or tempfloat2>125) tempfloat2=oldczerwony;
  oldczerwony=tempfloat2;
  Serial.print("Thermometer OnBoard temp3 = ");
  Serial.print(tempfloat3, 2);
  Serial.print(", sliding temp1 = ");
  Serial.print(tempfloat1, 2); 
  Serial.print(", czekamy = ");
  Serial.print(czekamy);   
  Serial.print(", on module 1 temp2 = ");
  Serial.println(tempfloat2, 2);

  //send feed at the same moment

  if ( czekamy > GRACE )
       {
            group -> set("temp1",tempfloat1);
            group -> set("temp4",tempfloat1 - 3.54);  //compens 1
            group -> set("temp5",tempfloat1 * 0.882920642);  //compens 2
       }
       
    else   
      {
            group -> set("temp1","NA"); //slidng
            group -> set("temp4","NA"); //wypelniamy bez wartosci dla synchronizacji
            group -> set("temp5","NA"); //wypelniamy bez wartosci dla synchronizacji
      }


  group -> set("temp2",tempfloat2); //real
  group -> set("temp3",tempfloat3);  //raw

  group -> save(); //one package? NOT WORKING, next aio.run() stops or restarts Arduino

  delay(60000);

}



Geyoyo
 
Posts: 7
Joined: Sat Dec 07, 2019 11:38 am

Re: group save on Arduino UNO Wifi Rev2 with "Adafruit IO Ar

by brubell on Mon Dec 09, 2019 11:18 am

It's possible that there's an issue with how you're publishing to the group. It looks like the client is disconnecting you after an invalid publish, and then reconnecting on the next io.loop(), publishing again, and failing/disconnecting.

You can try printing io.status() to see if it gets disconnected (AIO_DISCONNECT) after a group publish to confirm this. If this is the case, let me know and I'll assist you with debugging.

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

Re: group save on Arduino UNO Wifi Rev2 with "Adafruit IO Ar

by Geyoyo on Tue Dec 10, 2019 6:22 pm

Thank you very much for answer!

brubell wrote:It's possible that there's an issue with how you're publishing to the group. It looks like the client is disconnecting you after an invalid publish, and then reconnecting on the next io.loop(), publishing again, and failing/disconnecting.

You can try printing io.status() to see if it gets disconnected (AIO_DISCONNECT) after a group publish to confirm this. If this is the case, let me know and I'll assist you with debugging.




group save without aio.run was working this way with additional information (because "AIO_DISCONNECT was not declared in this scope", so I used AIO_CONNECTED):

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
Thermometer OnBoard temp3 = 26.06, sliding temp1 = 2.61, czekamy = 1, on module 1 temp2 = 24.50
after group save, AIO_CONNECTED=21   aio.status=21
Thermometer OnBoard temp3 = 26.12, sliding temp1 = 5.22, czekamy = 2, on module 1 temp2 = 24.44
after group save, AIO_CONNECTED=21   aio.status=21




I have seen start of feeding at 9:54:02pm,
start.png
start.png (47.76 KiB) Viewed 149 times

and then it stopped at 10:17:21pm,
stopped.png
stopped.png (53.7 KiB) Viewed 149 times

but the program was still runing and aio.status didn't changed - it was about 10:30.

Code: Select all | TOGGLE FULL SIZE
Thermometer OnBoard temp3 = 25.81, sliding temp1 = 25.59, czekamy = 26, on module 1 temp2 = 24.31
after group save, AIO_CONNECTED=21   aio.status=21


(I hoped that aio.status will show "disconnected", and I will be able to aio.connect, but there is no such situation, aio.status still shows "connected", and no data is sent after about 23 minutes.)

Then I uncommented aio.run, and Arduino at second aio.run() probably had freezed as before.
There was one new data point at 10:35 and than nothing, program didn't reach second time printing of temperatures.

onegroupsave.png
onegroupsave.png (31.75 KiB) Viewed 149 times


(temp1 is not visible on charts because in real program it is filtered out with GRACE on the beginning)

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
Thermometer OnBoard temp3 = 25.81, sliding temp1 = 2.58, czekamy = 1, on module 1 temp2 = 24.44
after group save, AIO_CONNECTED=21   aio.status=21



Actual changed code, idea of:
Code: Select all | TOGGLE FULL SIZE
.....
byte led=HIGH;
.....

void loop()
{


  aio.run();  // keep client connected to AIO service

Serial.println ("temp1 = 23.56, temp 2 = 34.80, temp3 = 24,13");

  group -> set("temp1",tempfloat1);
  group -> set("temp2",tempfloat2);
  group -> set("temp3",tempfloat3);

  group -> save();

Serial.print("after group save, AIO_CONNECTED="); Serial.print(AIO_CONNECTED); 
//AIO_DISCONNECT was not declared in this scope
Serial.print("   aio.status="); Serial.println(aio.status());

for ( i = 0; i < 60 ; i++) //I want to see if Arduino is alive
   {
     if (led) digitalWrite(LED_BUILTIN, LOW);
       else digitalWrite(LED_BUILTIN, HIGH);

     led = !led;

     delay(1000);
   }

}

Geyoyo
 
Posts: 7
Joined: Sat Dec 07, 2019 11:38 am

Re: group save on Arduino UNO Wifi Rev2 with "Adafruit IO Ar

by Geyoyo on Sat Dec 14, 2019 2:55 pm

I was able to switch on debugging in Adafruit_IO_Arduino,
changed aio.run to:

Code: Select all | TOGGLE FULL SIZE
void AdafruitIO::run(uint16_t busywait_ms)
{
  // loop until we have a connection
 
  AIO_DEBUG_PRINTLN("run debug - loop until we have a connection");
 
  while(mqttStatus() != AIO_CONNECTED){}
 
  AIO_DEBUG_PRINTLN("run debug - after loop until we have a connection");
 
  if(busywait_ms > 0)
    _packetread_timeout = busywait_ms;

  AIO_DEBUG_PRINT("run debug - before _mqtt process packets,  _packetread_timeout = "); AIO_DEBUG_PRINTLN(_packetread_timeout);


  _mqtt->processPackets(_packetread_timeout);
 
  AIO_DEBUG_PRINTLN("run debug - after _mqtt process packets");

  // ping to keep connection alive if needed
  if(millis() > (_last_ping + AIO_PING_INTERVAL)) {
     AIO_DEBUG_PRINTLN("run debug - before _mqtt ping");    
    _mqtt->ping();
    AIO_DEBUG_PRINTLN("run debug - after _mqtt ping");    
    _last_ping = millis();
  }
 
  AIO_DEBUG_PRINTLN("run debug - end of ::run");
}



and got such output:

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO debug connect- AdafruitIO::connect()

Adafruit IO connected.
Setup aio.run
run debug - loop until we have a connection
run debug - after loop until we have a connection
run debug - before _mqtt process packets,  _packetread_timeout = 100
run debug - after _mqtt process packets
run debug - end of ::run
before loop aio.run, AIO_CONNECTED=21   aio.status=21
run debug - loop until we have a connection
run debug - after loop until we have a connection
run debug - before _mqtt process packets,  _packetread_timeout = 100
run debug - after _mqtt process packets
run debug - end of ::run
after loop aio.run, AIO_CONNECTED=21   aio.status=21
Thermometer OnBoard temp3 = 25.94, sliding temp1 = 2.59, on module 1 temp2 = 24.12
after group save, AIO_CONNECTED=21   aio.status=21
before loop aio.run, AIO_CONNECTED=21   aio.status=21
run debug - loop until we have a connection
run debug - after loop until we have a connection
run debug - before _mqtt process packets,  _packetread_timeout = 100




Program freezes on third aio.run (one setup, one first loop, next loop freeze).
And inside aio.run it stops on _mqtt->processPackets
which I think leads to Adafruit_MQTT_Library v1.0.3, I added some debuging there:

Code: Select all | TOGGLE FULL SIZE
void Adafruit_MQTT::processPackets(int16_t timeout) {

  uint32_t elapsed = 0, endtime, starttime = millis();

  while (elapsed < (uint32_t)timeout) {
   
    Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
   
    Serial.println("_MQTT::processPackets debug - after readSubscription");

   
   
    if (sub) {

    Serial.print("_MQTT::processPackets debug - len(sub) =");Serial.print(sub->datalen);Serial.print(" sub =");Serial.println((char *)sub->lastread[1]);
   
       char bajty[100];
       memcpy(bajty, sub, 100);
       int i;
       for (i=0; i <= sub->datalen+2 ; i++)
       {
         
          Serial.print("Char "); if (  i<10 ) Serial.print("0");       Serial.print(i);
          Serial.print(" = \"");
          if (  byte(bajty[i]) == 10 || byte(bajty[i]) == 0 ) Serial.print(" ");
          else Serial.print(bajty[i]);

          Serial.print("\" (");
          Serial.print(byte(bajty[i]));Serial.println(")");
         
       }             
      
      Serial.println("_MQTT::processPackets debug - **** sub packet received from readSubscription");
      if (sub->callback_uint32t != NULL) {
   // huh lets do the callback in integer mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in integer mode");
   uint32_t data = 0;
   data = atoi((char *)sub->lastread);
   Serial.print("_MQTT::processPackets debug - *** calling int callback with : "); Serial.println(data);
   sub->callback_uint32t(data);
      }
      else if (sub->callback_double != NULL) {
   // huh lets do the callback in doublefloat mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in doublefloat mode");
   double data = 0;
   data = atof((char *)sub->lastread);
   Serial.print("_MQTT::processPackets debug - *** calling double callback with : "); Serial.println(data);
   sub->callback_double(data);
      }
      else if (sub->callback_buffer != NULL) {
   // huh lets do the callback in buffer mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in buffer mode");
   Serial.print("_MQTT::processPackets debug - *** calling buffer callback with : "); Serial.println((char *)sub->lastread);
   sub->callback_buffer((char *)sub->lastread, sub->datalen);
      }
      else if (sub->callback_io != NULL) {
        // huh lets do the callback in io mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in io mode");
        Serial.print("_MQTT::processPackets debug - *** calling io instance callback with : ");
   
   Serial.println((char *)sub->lastread);
   Serial.print(".");Serial.print(".");Serial.print(".");Serial.print(".");Serial.print(".");Serial.println(".");
   Serial.println(" still working. ");
   delay(100);
   
        ((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);

   Serial.print(" passed .");Serial.print(".");Serial.print(".");Serial.print(".");Serial.print(".");Serial.println(".");
   delay(100);
      }
    }

    // keep track over elapsed time
    endtime = millis();
    if (endtime < starttime) {
      starttime = endtime; // looped around!")
    }
    elapsed += (endtime - starttime);
  }
 
  Serial.println("_MQTT::processPackets debug - end of function");
}



Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO debug connect- AdafruitIO::connect()

Adafruit IO connected.
before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - end of function
run debug - end of ::run
after loop aio.run, AIO_CONNECTED=21   aio.status=21
Thermometer OnBoard temp3 = 26.94, sliding temp1 = 2.69, on module 1 temp2 = 24.06
after group save, AIO_CONNECTED=21   aio.status=21
before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - len(sub) =28 sub =
Char 00 = "⸮" (196)
Char 01 = "," (44)
Char 02 = " " (0)
Char 03 = "t" (116)
Char 04 = "e" (101)
Char 05 = "m" (109)
Char 06 = "p" (112)
Char 07 = "1" (49)
Char 08 = "," (44)
Char 09 = "N" (78)
Char 10 = "A" (65)
Char 11 = " " (10)
Char 12 = "t" (116)
Char 13 = "e" (101)
Char 14 = "m" (109)
Char 15 = "p" (112)
Char 16 = "2" (50)
Char 17 = "," (44)
Char 18 = "2" (50)
Char 19 = "." (46)
Char 20 = "4" (52)
Char 21 = "0" (48)
Char 22 = "6" (54)
Char 23 = "2" (50)
Char 24 = "5" (53)
Char 25 = "0" (48)
Char 26 = "e" (101)
Char 27 = "+" (43)
Char 28 = "0" (48)
Char 29 = "1" (49)
Char 30 = " " (10)
_MQTT::processPackets debug - **** sub packet received from readSubscription
_MQTT::processPackets debug - huh lets do the callback in io mode
_MQTT::processPackets debug - *** calling io instance callback with : temp1,NA
temp2,2.406250e+01

......
 still working.
⸮Processor came out of reset.

Connecting to Adafruit IO debug connect- AdafruitIO::connect()



On first run nothing is done in _MQTT::processPackets,
but on second time (I removed aio.run from setup(), it is colled next time very soon), after group save, something changes, this time "sub" is received by readSubscription, (28 Bytes?)
and than four types are checked;
uint32t, double, buffer fails and "io mode is confirmed", and somewhere around

Code: Select all | TOGGLE FULL SIZE
       
        ((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);


board restarts. I don't know what else I can check because do not understand above line of code, is it function/procedure call? Which one?

Geyoyo
 
Posts: 7
Joined: Sat Dec 07, 2019 11:38 am

Re: group save on Arduino UNO Wifi Rev2 with "Adafruit IO Ar

by Geyoyo on Sun Dec 15, 2019 4:26 pm

If I cannot bite

Code: Select all | TOGGLE FULL SIZE
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);


I added some more information for debug:

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - end of function
after loop aio.run, AIO_CONNECTED=21   aio.status=21
sliding temp1 = NA, external no 1 temp2 = 24.12
after group save, AIO_CONNECTED=21before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - len(sub) =28 sub =
Char 00 = "⸮" (C0 192)
Char 01 = "," (2C 44)
Char 02 = " " (00 0)
Char 03 = "t" (74 116)
Char 04 = "e" (65 101)
Char 05 = "m" (6D 109)
Char 06 = "p" (70 112)
Char 07 = "1" (31 49)
Char 08 = "," (2C 44)
Char 09 = "N" (4E 78)
Char 10 = "A" (41 65)
Char 11 = " " (0A 10)
Char 12 = "t" (74 116)
Char 13 = "e" (65 101)
Char 14 = "m" (6D 109)
Char 15 = "p" (70 112)
Char 16 = "2" (32 50)
Char 17 = "," (2C 44)
Char 18 = "2" (32 50)
Char 19 = "." (2E 46)
Char 20 = "4" (34 52)
Char 21 = "1" (31 49)
Char 22 = "2" (32 50)
Char 23 = "5" (35 53)
Char 24 = "0" (30 48)
Char 25 = "0" (30 48)
Char 26 = "e" (65 101)
Char 27 = "+" (2B 43)
Char 28 = "0" (30 48)
Char 29 = "1" (31 49)
Char 30 = " " (0A 10)
_MQTT::processPackets debug - **** sub packet received from readSubscription
_MQTT::processPackets debug - huh lets do the callback in io mode
_MQTT::processPackets debug - *** calling io instance callback with : temp1,NA
temp2,2.412500e+01
<=end<= of sub
 still working.
⸮Processor came out of reset.


and than go back to discrete feeding.

Code: Select all | TOGGLE FULL SIZE
  //try to send feed at the same moment

  if ( czekamy > GRACE )
       {
            temp1feed -> save(tempfloat1);//group -> set("temp1",tempfloat1); //slidng
       }
    else   
      {
            temp1feed -> save("NA"); //group -> set("temp1","NA"); //slidng
      }

  temp2feed -> save(tempfloat2); //group -> set("temp2",tempfloat2); //real

  //group -> save(); //sending in one time packet, NOT WORKING, next aio.run() restarts board

Serial.println("after 2 feeds");


and with above I got this:

Code: Select all | TOGGLE FULL SIZE
Processor came out of reset.

Connecting to Adafruit IO
Adafruit IO connected.
before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - end of function
after loop aio.run, AIO_CONNECTED=21   aio.status=21
sliding temp1 = NA, external no 1 temp2 = 23.94
after 2 feeds
before loop aio.run, AIO_CONNECTED=21   aio.status=21
_MQTT::processPackets debug - after readSubscription
_MQTT::processPackets debug - len(sub) =14 sub =
Char 00 = "⸮" (CC 204)
Char 01 = "," (2C 44)
Char 02 = " " (00 0)
Char 03 = "N" (4E 78)
Char 04 = "A" (41 65)
Char 05 = "," (2C 44)
Char 06 = "0" (30 48)
Char 07 = "." (2E 46)
Char 08 = "0" (30 48)
Char 09 = "," (2C 44)
Char 10 = "0" (30 48)
Char 11 = "." (2E 46)
Char 12 = "0" (30 48)
Char 13 = "," (2C 44)
Char 14 = "0" (30 48)
Char 15 = "." (2E 46)
Char 16 = "0" (30 48)
Char 17 = " " (00 0)
Char 18 = " " (00 0)
_MQTT::processPackets debug - **** sub packet received from readSubscription
_MQTT::processPackets debug - huh lets do the callback in io mode
_MQTT::processPackets debug - *** calling io instance callback with : NA,0.0,0.0,0.0<=end<= of sub
 still working.
 passed .
_MQTT::processPackets debug - end of function
Adafruit_MQTT::processPacketsUntil debug - Dropped a packet
Adafruit_MQTT::processPacketsUntil debug - Dropped a packet
Adafruit_MQTT::processPacketsUntil debug - Dropped a packet
after loop aio.run, AIO_CONNECTED=21   aio.status=21
sliding temp1 = NA, external no 1 temp2 = 23.94
after 2 feeds


Adafruit_MQTT::processPackets reads only one feed, also tries to make "io instance callback", and succeds.
Data is formated in diferent way than group packet,

With feeds there is set value and (empty) location for feed1
Code: Select all | TOGGLE FULL SIZE
NA,0.0,0.0,0.0


in group there were label of feed and only value, but for every feed:
Code: Select all | TOGGLE FULL SIZE
temp1,NA
temp2,2.412500e+01


And first is working, second is restarting Arduino.

Any ideas how to make group->save working?

So code is now like this

Code: Select all | TOGGLE FULL SIZE
//ARDUINO megaAVR boards v1.8.4
#include "SparkFunLSM6DS3.h"  //v1.0.0
#include "Wire.h"  //??
#include "SPI.h" //??

LSM6DS3 myIMU(SPI_MODE, SPIIMU_SS); //Default constructor is I2C, addr 0x6B


#include <OneWire.h>  //Jim Studt.... v2.3.5
#include <DallasTemperature.h>  //v3.8.0

OneWire oneWire( A3 ); //Podłączenie termometrow do A3, a3 sig + GND, 5V
DallasTemperature sensors( &oneWire ); //Przekazania informacji do biblioteki


//// Defines
#define AIO_USERNAME    "xxxxxxxxxxxxxxxxxxxxx"
#define AIO_KEY         "xxxxxxxxxxxxxxxxxxxx"
#define AIO_TEMP1       "temp1"
#define AIO_TEMP2       "temp2"
#define AIO_TEMP3       "temp3"
#define WIFI_SSID       "xxxxxxxxxxxx"
#define WIFI_PASS       "xxxxxxxxxxxx"
#define USE_AIRLIFT     // required for Arduino Uno WiFi R2 board compatability
byte led=HIGH;

// Libraries
#include <AdafruitIO_WiFi.h> //v3.2.3

// Constructors
AdafruitIO_WiFi aio(AIO_USERNAME, AIO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, SPIWIFI_RESET, NINA_GPIO0, &SPI);
AdafruitIO_Feed *temp1feed = aio.feed(AIO_TEMP1);
AdafruitIO_Feed *temp2feed = aio.feed(AIO_TEMP2);
//AdafruitIO_Feed *temp3feed = aio.feed(AIO_TEMP3);
//AdafruitIO_Feed *temp4feed = aio.feed(AIO_TEMP4);
//AdafruitIO_Feed *temp5feed = aio.feed(AIO_TEMP5);

// set up the group
AdafruitIO_Group *group = aio.group("default");

float tempfloat1,tempfloat2, tempfloat3, tempfloat4, tempfloat5, oldzielony=25, oldczerwony=25;
#define SLIDING 10
#define GRACE 25  //tyle MINUT trzeba na ustabilizowanie Onboard termometer
int czekamy = 0 , pozycja = 0, i;
//#define delta 2.6
float temps[SLIDING], suma;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(1000); //relax...
  Serial.println("Processor came out of reset.\n");
 
  //Call .begin() to configure the IMU
  myIMU.begin();
 
  sensors.begin(); //Inicjalizacja czujnikow temperatury


     // Adafruit IO connection and configuration
   Serial.print("Connecting to Adafruit IO");
   aio.connect();  // connect to Adafruit IO service
   while(aio.status() < AIO_CONNECTED) {
      Serial.print(".");
      delay(1000);  // wait 1 second between checks
   }
   Serial.println();
   Serial.println(aio.statusText());  // print AIO connection status

//Serial.println("Setup aio.run");
//   aio.run();//aio run comming soon
}


void loop()
{

Serial.print("before loop aio.run, AIO_CONNECTED="); Serial.print(AIO_CONNECTED);  //AIO_DISCONNECT was not declared in this scope
Serial.print("   aio.status="); Serial.println(aio.status());  //AIO_DISCONNECT was not declared in this scope

  aio.run();  // keep client connected to AIO service

Serial.print("after loop aio.run, AIO_CONNECTED="); Serial.print(AIO_CONNECTED);  //AIO_DISCONNECT was not declared in this scope
Serial.print("   aio.status="); Serial.println(aio.status());  //AIO_DISCONNECT was not declared in this scope
 
  tempfloat3=myIMU.readTempC(); //raw
  temps[pozycja++] = tempfloat3;
  if ( pozycja > SLIDING -1 ) pozycja = 0; //krecimy sie po tablicy

  if ( czekamy <= GRACE )
          czekamy++ ; //po grace juz nie zmieniamy "czekamy"

  suma = 0 ;
  for ( i = 0; i < SLIDING ; i++) suma = suma + temps[i];
   
  tempfloat1 = suma / SLIDING; 


  sensors.requestTemperatures();
 
  tempfloat2=sensors.getTempCByIndex(0);
  if (tempfloat2<-30 or tempfloat2>125) tempfloat2=oldczerwony;
  oldczerwony=tempfloat2;
  Serial.print("sliding temp1 = ");
  if ( czekamy > GRACE ) Serial.print(tempfloat1, 2);
  else Serial.print("NA");
  Serial.print(", external no 1 temp2 = ");
  Serial.println(tempfloat2, 2);
 

  //try to send feed at the same moment

  if ( czekamy > GRACE )
       {
            temp1feed -> save(tempfloat1);//group -> set("temp1",tempfloat1); //slidng
       }
    else   
      {
            temp1feed -> save("NA"); //group -> set("temp1","NA"); //slidng
      }

  temp2feed -> save(tempfloat2); //group -> set("temp2",tempfloat2); //real

  //group -> save(); //sending in one time packet, NOT WORKING, next aio.run() restarts board

Serial.println("after 2 feeds");
 
for ( i = 0; i < 60 ; i++) //I want to see if Arduino is alive
   {
     if (led) digitalWrite(LED_BUILTIN, LOW);
       else digitalWrite(LED_BUILTIN, HIGH);

     led = !led;

     delay(1000);
   }

}


And changed Adafruit_MQTT.cpp, Adafruit_MQTT::processPackets for debug:

Code: Select all | TOGGLE FULL SIZE
void Adafruit_MQTT::processPackets(int16_t timeout) {

  uint32_t elapsed = 0, endtime, starttime = millis();

  while (elapsed < (uint32_t)timeout) {
   
    Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
   
    Serial.println("_MQTT::processPackets debug - after readSubscription");

   
   
    if (sub) {

    Serial.print("_MQTT::processPackets debug - len(sub) =");Serial.print(sub->datalen);Serial.print(" sub =");Serial.println((char *)sub->lastread[1]);
   
       char bajty[100];
       memcpy(bajty, sub, 100);
       int i;
       for (i=0; i <= sub->datalen+4 ; i++)
       {
         
          Serial.print("Char "); if (  i<10 ) Serial.print("0");       Serial.print(i);
          Serial.print(" = \"");
          if (  byte(bajty[i]) == 10 || byte(bajty[i]) == 0 ) Serial.print(" ");
          else Serial.print(bajty[i]);

          Serial.print("\" (");if ( byte(bajty[i]) < 16 ) Serial.print("0"); Serial.print(byte(bajty[i]), HEX);Serial.print(" ");
          Serial.print(byte(bajty[i]));
         
          Serial.println(")");
         
       }             
      
      Serial.println("_MQTT::processPackets debug - **** sub packet received from readSubscription");
      if (sub->callback_uint32t != NULL) {
   // huh lets do the callback in integer mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in integer mode");
   uint32_t data = 0;
   data = atoi((char *)sub->lastread);
   Serial.print("_MQTT::processPackets debug - *** calling int callback with : "); Serial.println(data);
   sub->callback_uint32t(data);
      }
      else if (sub->callback_double != NULL) {
   // huh lets do the callback in doublefloat mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in doublefloat mode");
   double data = 0;
   data = atof((char *)sub->lastread);
   Serial.print("_MQTT::processPackets debug - *** calling double callback with : "); Serial.println(data);
   sub->callback_double(data);
      }
      else if (sub->callback_buffer != NULL) {
   // huh lets do the callback in buffer mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in buffer mode");
   Serial.print("_MQTT::processPackets debug - *** calling buffer callback with : "); Serial.println((char *)sub->lastread);
   sub->callback_buffer((char *)sub->lastread, sub->datalen);
      }
      else if (sub->callback_io != NULL) {
        // huh lets do the callback in io mode
   Serial.println("_MQTT::processPackets debug - huh lets do the callback in io mode");
        Serial.print("_MQTT::processPackets debug - *** calling io instance callback with : ");
   
   Serial.print((char *)sub->lastread);Serial.println("<=end<= of sub");
   Serial.println(" still working. ");
   delay(100);
   
        ((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);

   Serial.println(" passed .");
   delay(100);
      }
    }

    // keep track over elapsed time
    endtime = millis();
    if (endtime < starttime) {
      starttime = endtime; // looped around!")
    }
    elapsed += (endtime - starttime);
  }
 
  Serial.println("_MQTT::processPackets debug - end of function");
}

Geyoyo
 
Posts: 7
Joined: Sat Dec 07, 2019 11:38 am

Re: group save on Arduino UNO Wifi Rev2 with "Adafruit IO Ar

by Geyoyo on Tue Dec 17, 2019 2:45 pm

Trying to understand what Adafruit_MQTT_Library Adafruit_MQTT::processPackets, and other code around it is doing, it suddenly striked me!!!
It is about subscriptions, and subscription seems as it is about getting data from cloud, I don't use any subscriptions (and I didn't ask for any).

After this though I commented this strange line, which is probably just variable assignment

Code: Select all | TOGGLE FULL SIZE
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);


and group->save was working 18h.

20191216 18h group save.png
20191216 18h group save.png (64.75 KiB) Viewed 90 times


Than I recover original MQTT library and commented _mqtt->processPackets inside AdafruitIO::run

Code: Select all | TOGGLE FULL SIZE
void AdafruitIO::run(uint16_t busywait_ms)
{
  // loop until we have a connection
  while(mqttStatus() != AIO_CONNECTED){}

  if(busywait_ms > 0)
    _packetread_timeout = busywait_ms;

  //_mqtt->processPackets(_packetread_timeout);//***************

  // ping to keep connection alive if needed
  if(millis() > (_last_ping + AIO_PING_INTERVAL)) {
    _mqtt->ping();
    _last_ping = millis();
  }
}


And it worked again for many hours!

So now I have simple question how to use this _mqtt->ping(); part in the main loop of my program, without changing official libraries?

The closed I came is error "Adafruit_MQTT* AdafruitIO::_mqtt is protected within context", after I tried to use this:

Code: Select all | TOGGLE FULL SIZE
aio._mqtt.ping();

Geyoyo
 
Posts: 7
Joined: Sat Dec 07, 2019 11:38 am

Please be positive and constructive with your questions and comments.