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

Feeds not updating
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.

Feeds not updating

by black1990gsx on Mon Feb 15, 2016 4:07 am

Trying to do the adafruit io basics digital input

Using the basic digital in code

Code: Select all | TOGGLE FULL SIZE
/***************************************************
  Adafruit MQTT Library ESP8266 Example

  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino

  Works great with Adafruit's Huzzah ESP board:
  ----> https://www.adafruit.com/product/2471
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Tony DiCola for Adafruit Industries.
  Adafruit IO example additions by Todd Treece.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

// function prototypes
void connect(void);

/****************************** Pins ******************************************/

#define BUTTON          2

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "...your SSID..."
#define WLAN_PASS       "...your password..."

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "...your AIO username (see https://accounts.adafruit.com)..."
#define AIO_KEY         "...your AIO key..."

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM  = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);/****************************** Feeds ***************************************/

// Setup a feed called 'button' for publishing changes.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char BUTTON_FEED[] PROGMEM = AIO_USERNAME "/feeds/button";
Adafruit_MQTT_Publish button = Adafruit_MQTT_Publish(&mqtt, BUTTON_FEED);

/*************************** Sketch Code ************************************/

// button state
int current = 0;
int last = -1;

void setup() {

  // set button pin as an input
  pinMode(BUTTON, INPUT_PULLUP);

  Serial.begin(115200);

  Serial.println(F("Adafruit IO Example"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // connect to adafruit io
  connect();

}

void loop() {

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

  // grab the current state of the button
  current = digitalRead(BUTTON);

  // return if the value hasn't changed
  if(current == last)
    return;

  int32_t value = (current == LOW ? 1 : 0);

  // Now we can publish stuff!
  Serial.print(F("\nSending button value: "));
  Serial.print(value);
  Serial.print("... ");

  if (! button.publish(value))
    Serial.println(F("Failed."));
  else
    Serial.println(F("Success!"));

  // save the button state
  last = current;

}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}





The code seems to work as I get this in the serial debug

Adafruit IO Connected!

Sending button value: 1... Success!

Sending button value: 0... Success!

Sending button value: 1... Success!

Sending button value: 0... Success!

Sending button value: 1... Success!

Sending button value: 0... Success!



And yes I replaced all items I needed to for my AIO account, key and wi fi items as well as feed and so on..I have tried to recreate my dash board numerous times

I just want to see the Gage read 0 or 1 whe I press the button.

At a loss here

Thanks for help

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by clemens on Mon Feb 15, 2016 9:49 am

What do you see on Adafruit IO? Do you see the automatically created feeds in the feed section?

clemens
 
Posts: 41
Joined: Fri Jan 06, 2012 12:21 am

Re: Feeds not updating

by black1990gsx on Mon Feb 15, 2016 7:03 pm

I'm not sure what you mean by automatically created ones. I create the feed myself it it doesn't seem to change state

Thanks,

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by black1990gsx on Wed Feb 17, 2016 12:48 am

I went ahead and tried the actual MQTT esp8266 example.

I also turned on debug and got this

Connect result: 1
MQTT connect packet:
[0x10], Z [0x5A], [0x00], [0x06], M [0x4D], Q [0x51], I [0x49], s [0x73],
d [0x64], p [0x70], [0x03], Â [0xC2], [0x01], , [0x2C], [0x00], [0x14],
2 [0x32], 2 [0x32], : [0x3A], 4 [0x34], 2 [0x32], : [0x3A], 5 [0x35], 4 [0x34],
b [0x62], l [0x6C], a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39],
0 [0x30], g [0x67], s [0x73], x [0x78], [0x00], [0x0C], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], [0x00], ( [0x28], e [0x65], 6 [0x36], 3 [0x33], 0 [0x30],
f [0x66], b [0x62], c [0x63], 5 [0x35], 4 [0x34], d [0x64], 0 [0x30], 9 [0x39],
c [0x63], 3 [0x33], 1 [0x31], f [0x66], e [0x65], e [0x65], 3 [0x33], d [0x64],
4 [0x34], 8 [0x38], e [0x65], 9 [0x39], 1 [0x31], 5 [0x35], 6 [0x36], 7 [0x37],
7 [0x37], 0 [0x30], 3 [0x33], a [0x61], 3 [0x33], a [0x61], e [0x65], 8 [0x38],
0 [0x30], a [0x61], a [0x61], 3 [0x33],
sendPacket returned: 92
Read packet: [0x20], [0x02], [0x00], [0x00],
MQTT subscription packet:
‚ [0x82], [0x1D], ­ [0xAD], ¯ [0xAF], [0x00], [0x18], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], / [0x2F], f [0x66], e [0x65], e [0x65], d [0x64], s [0x73],
/ [0x2F], o [0x6F], n [0x6E], o [0x6F], f [0x66], f [0x66], [0x00],
sendPacket returned: 31
Read packet: � [0x90], [0x03], ­ [0xAD], ¯ [0xAF], [0x00],
SUBACK: � [0x90], [0x03], ­ [0xAD], ¯ [0xAF], [0x00],
MQTT Connected!

Sending photocell val 0...MQTT publish packet:
0 [0x30], [0x1F], [0x00], [0x1C], b [0x62], l [0x6C], a [0x61], c [0x63],
k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67], s [0x73], x [0x78],
/ [0x2F], f [0x66], e [0x65], e [0x65], d [0x64], s [0x73], / [0x2F], p [0x70],
h [0x68], o [0x6F], t [0x74], o [0x6F], c [0x63], e [0x65], l [0x6C], l [0x6C],
0 [0x30],
sendPacket returned: 33
OK!

Sending photocell val 1...MQTT publish packet:
0 [0x30], [0x1F], [0x00], [0x1C], b [0x62], l [0x6C], a [0x61], c [0x63],
k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67], s [0x73], x [0x78],
/ [0x2F], f [0x66], e [0x65], e [0x65], d [0x64], s [0x73], / [0x2F], p [0x70],
h [0x68], o [0x6F], t [0x74], o [0x6F], c [0x63], e [0x65], l [0x6C], l [0x6C],
1 [0x31],
sendPacket returned: 33
OK!


My feed photocell still wont update.

really needing help with this one

I have even tried to wipe my feeds and dashboard starting with new AIO key

just looking for the next step to try

Thanks,

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by black1990gsx on Wed Feb 17, 2016 3:49 am

I am able to send data to the esp8266 from adafuit i/o just fine using the on/off example.

I still can't get data from esp8266 to the adafruit io broker.

Alos when I add another feed as a subscriber I get the following at it can;t even connect to adafruit io

Connecting to MQTT... Connecting to: io.adafruit.com
Connect result: 0
Connection failed
Retrying MQTT connection in 5 seconds...
Connecting to: io.adafruit.com
Connect result: 1
MQTT connect packet:
[0x10], Z [0x5A], [0x00], [0x06], M [0x4D], Q [0x51], I [0x49], s [0x73],
d [0x64], p [0x70], [0x03], Â [0xC2], [0x01], , [0x2C], [0x00], [0x14],
0 [0x30], 1 [0x31], : [0x3A], 4 [0x34], 3 [0x33], : [0x3A], 2 [0x32], 6 [0x36],
b [0x62], l [0x6C], a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39],
0 [0x30], g [0x67], s [0x73], x [0x78], [0x00], [0x0C], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], [0x00], ( [0x28], e [0x65], 6 [0x36], 3 [0x33], 0 [0x30],
f [0x66], b [0x62], c [0x63], 5 [0x35], 4 [0x34], d [0x64], 0 [0x30], 9 [0x39],
c [0x63], 3 [0x33], 1 [0x31], f [0x66], e [0x65], e [0x65], 3 [0x33], d [0x64],
4 [0x34], 8 [0x38], e [0x65], 9 [0x39], 1 [0x31], 5 [0x35], 6 [0x36], 7 [0x37],
7 [0x37], 0 [0x30], 3 [0x33], a [0x61], 3 [0x33], a [0x61], e [0x65], 8 [0x38],
0 [0x30], a [0x61], a [0x61], 3 [0x33],
sendPacket returned: 92
Read packet: [0x20], [0x02], [0x00], [0x00],
MQTT subscription packet:
‚ [0x82], [0x1D], ­ [0xAD], ¯ [0xAF], [0x00], [0x18], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], / [0x2F], f [0x66], e [0x65], e [0x65], d [0x64], s [0x73],
/ [0x2F], o [0x6F], n [0x6E], o [0x6F], f [0x66], f [0x66], [0x00],
sendPacket returned: 31
Read packet: � [0x90], [0x03], ­ [0xAD], ¯ [0xAF], [0x00],
SUBACK: � [0x90], [0x03], ­ [0xAD], ¯ [0xAF], [0x00],
MQTT subscription packet:
‚ [0x82], [0x1E], ­ [0xAD], ¯ [0xAF], [0x00], [0x19], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], / [0x2F], f [0x66], e [0x65], e [0x65], d [0x64], s [0x73],
/ [0x2F], s [0x73], l [0x6C], i [0x69], d [0x64], e [0x65], r [0x72], [0x00],

sendPacket returned: 32
Read packet: 2 [0x32], [0x1E], [0x00], [0x18], b [0x62],
SUBACK: 2 [0x32], [0x1E], [0x00], [0x18], b [0x62],
Failed to subscribe
Retrying MQTT connection in 5 seconds...
Connecting to: io.adafruit.com
Connect result: 1
MQTT connect packet:
[0x10], Z [0x5A], [0x00], [0x06], M [0x4D], Q [0x51], I [0x49], s [0x73],
d [0x64], p [0x70], [0x03], Â [0xC2], [0x01], , [0x2C], [0x00], [0x14],
0 [0x30], 1 [0x31], : [0x3A], 4 [0x34], 3 [0x33], : [0x3A], 2 [0x32], 6 [0x36],
b [0x62], l [0x6C], a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39],
0 [0x30], g [0x67], s [0x73], x [0x78], [0x00], [0x0C], b [0x62], l [0x6C],
a [0x61], c [0x63], k [0x6B], 1 [0x31], 9 [0x39], 9 [0x39], 0 [0x30], g [0x67],
s [0x73], x [0x78], [0x00], ( [0x28], e [0x65], 6 [0x36], 3 [0x33], 0 [0x30],
f [0x66], b [0x62], c [0x63], 5 [0x35], 4 [0x34], d [0x64], 0 [0x30], 9 [0x39],
c [0x63], 3 [0x33], 1 [0x31], f [0x66], e [0x65], e [0x65], 3 [0x33], d [0x64],
4 [0x34], 8 [0x38], e [0x65], 9 [0x39], 1 [0x31], 5 [0x35], 6 [0x36], 7 [0x37],
7 [0x37], 0 [0x30], 3 [0x33], a [0x61], 3 [0x33], a [0x61], e [0x65], 8 [0x38],
0 [0x30], a [0x61], a [0x61], 3 [0x33],
sendPacket returned: 92
Connection failed

If I remove one of the subscriptions from the code it connect's fine

Thanks

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by adafruit2 on Wed Feb 17, 2016 11:37 am

are you using the very latest adafruit_mqtt? we recently updated it

adafruit2
Site Admin
 
Posts: 19408
Joined: Fri Mar 11, 2005 7:36 pm

Re: Feeds not updating

by black1990gsx on Wed Feb 17, 2016 7:29 pm

I'm using 11.1

thanks

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by black1990gsx on Wed Feb 17, 2016 7:48 pm

Just tried both 12.0 and 12.1

I can now get more than 1 sub working but still no go for publishing to a feed

Thanks,

black1990gsx
 
Posts: 6
Joined: Mon Feb 15, 2016 2:42 am

Re: Feeds not updating

by pyremage on Sat Feb 20, 2016 10:52 am

I've said a while back that this is a problem for me as well, in the post viewtopic.php?f=56&t=89046 and it is still a problem today.

I am publishing the value of 4 different digital lines to gauge boxes, either a 0 or a 1, but they do not reflect the data. If I look at the feeds, they never change to show having received a 1 from an active line. The serial port is showing that AIO is acknowledging having received the data.

I need a more reliable way to keep the MCU and AIO synchronized, but until I work that out I need a simple indicator that they are not. I created feedback to show me this but AIO is not cooperating...as I said before, a simple lamp box would be great.

pyremage
 
Posts: 18
Joined: Mon Aug 27, 2012 10:05 am

Please be positive and constructive with your questions and comments.