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

Adafruit IO and Esp Now
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.

Adafruit IO and Esp Now

by Kitkate on Mon Sep 07, 2020 5:10 pm

So i am using a esp now sender sending an array of 8 binary element at a 12.5ms interval. The problem is on the reciever side I am using both adafruit io and esp now, so for some reason enabling adafruit io slows down esp now by alot of seconds maybe close to 1. That is I can see the updated array after 1 second. So what could be the reason behind it?

Kitkate
 
Posts: 9
Joined: Sun Jun 07, 2020 1:25 pm

Re: Adafruit IO and Esp Now

by brubell on Wed Sep 09, 2020 10:46 am

I haven't tried ESPNow with Adafruit IO. Do you have an example sketch or more details? The delay is likely caused by polling the MQTT broker for new messages.

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

Re: Adafruit IO and Esp Now

by Kitkate on Wed Sep 09, 2020 3:23 pm

It works the same, with or without adding a timer delay to io.run
Code: Select all | TOGGLE FULL SIZE
#include <esp_now.h>
#include <WiFi.h>
#include <AdafruitIO.h>
#include "AdafruitIO_WiFi.h"

#define IO_USERNAME "Not Gonna Tell Ya"
#define IO_KEY "Gibberish"
#define WIFI_SSID "SomeDevice"
#define WIFI_PASS "ThinkOfNumbers"

AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
typedef struct struct_message {
  String stepdetection[8]={"False"};
} struct_message;
struct_message myData;


int brightval=100;
int prevbrightval=100;
String option= "illumination";
char optstr[50]= "illumination";
const char *menu[]= {"darkness","illumination","breathe","smart step","past present and future","chain reaction","visualise","piano tile"};
String stairnoteval;
int stairval;
String noteval;
int menunum= 1;
int i;
int tempvol,newvol,volume=50;
char temp[50];
unsigned long iotimer=0;
char* pointer;
 AdafruitIO_Feed *Mode = io.feed("Mode");
 AdafruitIO_Feed *Brightness = io.feed("Brightness");
 AdafruitIO_Feed *NoteSet = io.feed("NoteSet");
 AdafruitIO_Feed *Volume = io.feed("Volume");

 
void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
   if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
   esp_now_register_recv_cb(OnDataRecv);
  Serial.print("Connecting to Adafruit IO");
  io.connect();
  Mode-> onMessage(handleMode);
  Brightness-> onMessage(handleBrightness);
  NoteSet-> onMessage(handleNoteSet);
  Volume-> onMessage(handleVolume);
 
  while(io.status() < AIO_CONNECTED) {
   Serial.print(io.statusText());
    delay(500);
  }
  Serial.println("Done");
 
  Mode->get();
  Brightness->get();
  NoteSet-> get();
  Volume-> get();
  iotimer=millis();
}

void loop()
{
  for (i=0;i<8;i++){
  if (myData.stepdetection[i]== "True"){
    Serial.print("Step Detected On Stair Number ");
    Serial.println(i);
    }
  }
  if (millis()-iotimer>1000){
  io.run();
  iotimer=millis();
}
}

 void handleBrightness(AdafruitIO_Data *data) {
  brightval = data->toInt();
  Serial.print("Led Stairs Brightness is : ");
  if (brightval>100){
    brightval=prevbrightval;
    } else {
      prevbrightval= brightval;
      }
    Serial.println(brightval);
 }

 void handleMode(AdafruitIO_Data *data){
  option= data->toString();
  option.toCharArray(optstr,50);
  for (i=0;i<8;i++){
    pointer= strstr(optstr,menu[i]);
    if (pointer){
      menunum= i;
      }
    }
  Serial.print("The Option Selected Is : ");
  Serial.println(menu[menunum]);
  }
  void handleVolume(AdafruitIO_Data *data){
    newvol= data->toInt();
   if (tempvol>100){
    newvol=tempvol;
    } else {
      tempvol= newvol;
      }
    volume= round( map(newvol,0,100,0,30));
    Serial.println(volume);
    }
  void handleNoteSet(AdafruitIO_Data *data){
    stairnoteval= data->toString();
    stairval= atoi(stairnoteval.substring(0,1).c_str())-1;
    noteval= stairnoteval.substring(stairnoteval.indexOf(' ')+1);
    Serial.println(stairval);
    Serial.println(noteval);
    }
 
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
}
 

Kitkate
 
Posts: 9
Joined: Sun Jun 07, 2020 1:25 pm

Re: Adafruit IO and Esp Now

by brubell on Wed Sep 16, 2020 10:39 am

Do other MQTT services work with ESP Now? The timing within ESP Now may be too tight for MQTT.

Do you have a link to a tutorial you followed about setting up ESP Now?

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

Please be positive and constructive with your questions and comments.