0

AdafruitIO doesn't update with a value
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AdafruitIO doesn't update with a value

by 2wheelD on Fri Apr 05, 2019 7:38 pm

Using Arduino Uno with Arduino Ethernet shield and MQTT library to connect to Adafruit IO. I get and indication that there is a connection and that my info is published to my feed with the following code:

bool sent;
MQTT_connect();

//Send info to AdafruitIO
sent = mqtt.publish (FEED_PATH, n);
if(sent = true){
Serial.print(n++);
Serial.println(" got sent!!!");
}

I get a response that I expect: 0 got sent .......1 got sent .....2 got sent. But my AdafruitIO feed does not indicate any changes. Any ideas?

2wheelD
 
Posts: 3
Joined: Mon Jun 26, 2017 5:06 pm

Re: AdafruitIO doesn't update with a value

by brubell on Mon Apr 08, 2019 10:06 am

Could you post your full code within [code] tags,

Remember to remove the IO API Keys when posting

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

Re: AdafruitIO doesn't update with a value

by 2wheelD on Mon Apr 08, 2019 1:04 pm

Here is the code with "name" and Key removed:
Code: Select all | TOGGLE FULL SIZE
/*This is a test of the AdafruitIO scheme to work with IFTTT in sending me an SMS message when security triggers.
 *
 */

#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#include <Ethernet.h>
#include <Ethernetclient.h>
#include <SPI.h>
#include <Dns.h>
#include <Dhcp.h>

byte sdPin = 4; //SD control pin
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x55, 0x2A}; //MAC address of the Ethernet Board

#define AIO_SERVER   "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "my_username"
#define AIO_KEY   "my_key"
#define FEED_PATH AIO_USERNAME"/feeds/door/"

EthernetClient client; // Initialize the Ethernet client library
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
#define halt(s) { Serial.println(F( s )); while(1);

int repeat = 0;
int n = 0;

void setup() {
  Serial.begin(115200); //Turn on serial monitor
  pinMode(sdPin ,OUTPUT); //To prevent SD card interaction
  digitalWrite(sdPin, HIGH); //Turn off SD card slot on ethernet shield
  Serial.println(F("Adafruit MQTT demo"));
 
  // Initialise the Client
  Serial.print(F("\nInit the Client..."));
  Ethernet.begin(mac);
  delay(1000); //give the ethernet a second to initialize

}

void loop() {
  if (repeat < 3){
    door_open();
    repeat++;
  }
  delay(15000);
 
}

void door_open(){
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  bool sent = false;
  MQTT_connect();
                             
  //Send info to AdafruitIO
  sent = mqtt.publish (FEED_PATH, n);
  if(sent = true){
    Serial.print(n++);
    Serial.println(" got sent!!!");
  }
}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");
}

2wheelD
 
Posts: 3
Joined: Mon Jun 26, 2017 5:06 pm

Re: AdafruitIO doesn't update with a value

by 2wheelD on Sat Apr 13, 2019 12:49 pm

I corrected the line in my code: if (sent = true) to if (sent == true). Got the same result. Using the AdafruitIO monitor, I determined that I am connecting, but I get no change in my feed. So, apparently this part of my code is incorrect:
Code: Select all | TOGGLE FULL SIZE
  sent = mqtt.publish (FEED_PATH, n);
  if(sent == true){
    Serial.print(n++);
    Serial.println(" got sent!!!");
  }

Anyone know the proper method to update feeds using MQTT ?

2wheelD
 
Posts: 3
Joined: Mon Jun 26, 2017 5:06 pm

Re: AdafruitIO doesn't update with a value

by brubell on Fri Apr 19, 2019 10:53 am

Could you try updating Adafruit MQTT? I published an update to that library earlier this week which fixes a reported problem with ethernet.

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

Please be positive and constructive with your questions and comments.


cron