0

[object Object]
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

[object Object]

by cow9000 on Tue May 10, 2016 5:35 pm

So, I recently starting working with the ESP8266 Adafruit breakout (I think thats what it is called), and I got it working on a friends breakout. However, when I ran the code on another one, when I sent out 1, it came back as [object Object].

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
#define BUTTON2          0

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

#define WLAN_SSID       "xxxxx"
#define WLAN_PASS       "xxxx*"

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

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "xxxxxx"
#define AIO_KEY         "xxxxxx"

/************ 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/smarthome";
Adafruit_MQTT_Publish button = Adafruit_MQTT_Publish(&mqtt, BUTTON_FEED);

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

// button state
int current = 0;
int current2 = 0;
int last = -1;
int adding = 0;
void setup() {
 
  // set button pin as an input
  pinMode(2, INPUT);
  pinMode(0, INPUT);
  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() {
  //current = LOW;
  //current2 = LOW;
  current = digitalRead(BUTTON);
  current2 = digitalRead(BUTTON2);
  // ping adafruit io a few times to make sure we remain connected]
  adding ++;
  if(adding > 50){
    if(! mqtt.ping(3)) {
      // reconnect to adafruit io
      if(! mqtt.connected())
        connect();
    }
    adding = 0;
  }
  // grab the current state of the button
  // return if the value hasn't changed
  if(current == LOW){
 
  //int32_t value = (current == LOW ? 1 : 0);

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

  if (! button.publish(0)){
    Serial.println(F("FAILURE!"));
  }
  // save the button state
  //last = current;
  }else if(current2 == LOW){
 
  //int32_t value = (current == LOW ? 1 : 0);

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

  if (! button.publish(1)){
    Serial.println(F("FAILURE!"));
  }

  // 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!"));

}


Keep in mind that the xxxxx for the key and stuff are already filled in and are correct in my code on this computer, just put those xxxxx's for security.

cow9000
 
Posts: 2
Joined: Thu Apr 28, 2016 8:28 pm

Re: [object Object]

by light_dayforger on Tue May 10, 2016 7:39 pm

cow9000,

I have 3 rigs with the ESP8266 Huzzah, and until today they had been working fine. I started getting data being returned as [object Object] on all 3. I tried researching on the Internet but so far your thread is the only one reporting this error.

My guess is that we are seeing one of two things happening:
1. The MQTT protocol is failing somehow
2. There are problems with the Huzzah board.

These are the only common elements across all 3 rigs. I did a soft reset but that did nothing. Now I am doing a hard reset (full unplug from power) and will report on the outcome. Worst case scenario, I will have to fire up the Serial Monitor and see if the data is corrupted at the board level or at adafruit.io once it is received. Stay tuned!

-light_dayforger

light_dayforger
 
Posts: 23
Joined: Wed Apr 13, 2016 11:20 pm

Re: [object Object]

by light_dayforger on Tue May 10, 2016 8:36 pm

...ok I have done some additional testing.

1. I plugged the entire sensor rig to my computer and ran the code. The Serial Monitor code proved the following:
a. WiFi connection is successful.
b. No errors are thrown for MQTT dropping = read persistent connection.
c. Feeds get published to MQTT + the correct numeric data gets stored in the feed.
a, b, c were tested multiple times.

2. My conclusions are as follow:
a. It is not a problem with the ESP8266 Huzzah board: sensors are read properly, WiFi connectivity works, etc. etc.
b. It is not a code problem either: no compile or run-time errors.
c. The most likely culprit is that the MQTT broker, Adafruit.io, is not reading the data correctly:
i. On trying to create new widget for a dashboard, it acknowledges data has come in but it shows it as [object Object].
ii. The x-axis (time axis), has not updated to reflect the latest received data.

I am thinking this is temporary thing that should go away. If it persists, it will need more investigation!

light_dayforger

light_dayforger
 
Posts: 23
Joined: Wed Apr 13, 2016 11:20 pm

Re: [object Object]

by uniontownlabs on Tue May 10, 2016 9:01 pm

Sorry for the delay, but this issue should be resolved. Please let us know if you encounter this issue again.

uniontownlabs
 
Posts: 112
Joined: Wed Dec 17, 2014 10:56 pm

Re: [object Object]

by cow9000 on Tue May 10, 2016 10:08 pm

uniontownlabs wrote:Sorry for the delay, but this issue should be resolved. Please let us know if you encounter this issue again.


Thank you! It has been fixed.

cow9000
 
Posts: 2
Joined: Thu Apr 28, 2016 8:28 pm

Re: [object Object]

by light_dayforger on Tue May 10, 2016 10:42 pm

Ditto on what cow9000 said! It is back up. Thanks a lot!

light_dayforger
 
Posts: 23
Joined: Wed Apr 13, 2016 11:20 pm

Re: [object Object]

by wifixcort on Wed May 11, 2016 3:41 pm

I have the same problem yesterday. 1 of my feeds says [object Object], I have not changed anything and started to report bad. Today I saw that started operating

Today I find that another of my feeds is reporting wrong, it reports GPS and also I have not touched anything, it had worked well for weeks, until now began to fail.

https://drive.google.com/file/d/0B8m1zB3sRHQ_dzAxdHBoUmRzVVE/view?usp=sharing

wifixcort
 
Posts: 4
Joined: Mon Jan 25, 2016 9:23 am

Please be positive and constructive with your questions and comments.