Publishing data

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.
Locked
User avatar
robotdr
 
Posts: 6
Joined: Thu Aug 07, 2014 2:31 am

Publishing data

Post by robotdr »

I was invited into the beta of Adafruit.io a couple of weeks ago. Had been publishing some temperature data connecting via a ethernet shield and arduino. I received the Huzzah ESP8266 breakout this week and was going to try some of the projects on Adafruit learning this weekend. I had noticed my ethernet project had stopped updating to Adafruit.io earlier but did not have time to investigate. I set up the ESP 8266 and ran the "connecting via wifi" sketch and it ran successful connecting thru my home wifi network to Adafruit. Today I did the simple digital input sketch to publish the switch condition to adafruit.io with the ESP8266. Looking at the serial monitor I see it connect to my home wifi and get a IP address then it shows connecting to adafruit io and then shows "connected". I see the switch values changing and the "success" after each. The "button" feed I created on Adafruit.io shows no data being published.
I thought I would try the desktop MQTT.fx tutorial on Adafruit and see if I could push data to the button feed on Adadfruit.io with MQTT.fx. After following the tutorial and setting it up I am not seeing anything posted to the feed on adafruin.io. I am able to set up a "toggle button" on my Adafruit.io dashboard and when I subscribe to it on MQTT.fx I see responses on MQTT.fx when I change condition of toggle button on Adafruit.io.
I also tried regenerating another AIO key and changing that in my sketches and that made no difference. I was still able to connect to Adafruit.io with MQTT.fx after inputting the new key but do not see any data I publish with MQTT.fx.
Any ideas where I might be going wrong or something I might be missing. Thanks for your time and sorry this post is so long and confusing.

John

User avatar
Keebie81
 
Posts: 157
Joined: Wed Sep 10, 2014 6:53 pm

Re: Publishing data

Post by Keebie81 »

When you create a new block and are at step 2 where you choose feeds, do you see the feed name there with anything under last value? I have noticed sometimes when I select a feed it for some reason picks something else. Takes a few tries of editing the block and selecting the correct feed before it works.

User avatar
robotdr
 
Posts: 6
Joined: Thu Aug 07, 2014 2:31 am

Re: Publishing data

Post by robotdr »

Keebie81 wrote:When you create a new block and are at step 2 where you choose feeds, do you see the feed name there with anything under last value? I have noticed sometimes when I select a feed it for some reason picks something else. Takes a few tries of editing the block and selecting the correct feed before it works.
When I create a new block and at the point to select a feed the feed shows null under last value. This is the case when I have tried to push data to the feed from the esp8266 or using MQTT.fx from the desktop. If I go to the individual feed screen I never see any data there either. I can hover the mouse over a block and it shows the correct feed it is tied to in the corner. I have also tried pushing data to the default welcome-feed and have no luck there. I am sort of at a loss at this point.

User avatar
Keebie81
 
Posts: 157
Joined: Wed Sep 10, 2014 6:53 pm

Re: Publishing data

Post by Keebie81 »

robotdr wrote:
Keebie81 wrote:When you create a new block and are at step 2 where you choose feeds, do you see the feed name there with anything under last value? I have noticed sometimes when I select a feed it for some reason picks something else. Takes a few tries of editing the block and selecting the correct feed before it works.
When I create a new block and at the point to select a feed the feed shows null under last value. This is the case when I have tried to push data to the feed from the esp8266 or using MQTT.fx from the desktop. If I go to the individual feed screen I never see any data there either. I can hover the mouse over a block and it shows the correct feed it is tied to in the corner. I have also tried pushing data to the default welcome-feed and have no luck there. I am sort of at a loss at this point.
Could you post the code and just remove the key and wifi information

User avatar
robotdr
 
Posts: 6
Joined: Thu Aug 07, 2014 2:31 am

Re: Publishing data

Post by robotdr »

Keebie81,
I will post the code I used when I get home tonight. It is only the sketch from the digital in tutorial for Adafruit.io
Thanks

User avatar
robotdr
 
Posts: 6
Joined: Thu Aug 07, 2014 2:31 am

Re: Publishing data

Post by robotdr »

Keebie81
Below is the code I was using with my ESP8266 just trying to do a simple data publish to Adafruit.io before I set up the temperature monitor project which is my real goal. It is just the digital input sketch in one of the Adafruit.io tutorials. Running this sketch I get no data or switch conditions sent to my "button" feed.
I did notice one of the other post on the forum where someone was getting data on their feed but it was not transferring to their gauges. Different than my problem as I have no data in the button feed. Justin Cooper had the other person check for java script errors by " Right click on page, inspect element, then click the 'Console' option when the developer tools show up" I tried this and do have an error "The specified value '!' does not conform to the required format. The format is '#rrggbb' where rr, gg, bb are two-digit hexadecimal numbers." Not sure what this might mean.
I am using Chrome on a WIN 7 machine. I have tried Internet explorer, disabled antivirus, disabled firewall and tried a different computer and still unable to publish data. Sort of at a loss at this point.

Thanks
/***************************************************
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"

/****************************** 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 = AIO_KEY __DATE__ __TIME__;
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!"));

}

User avatar
Keebie81
 
Posts: 157
Joined: Wed Sep 10, 2014 6:53 pm

Re: Publishing data

Post by Keebie81 »

Robotdr,

I tried the code and it worked fine for me. When at the Serial output does it show the changes with pressing the button?
serial.jpg
serial.jpg (37.53 KiB) Viewed 781 times
When creating the block do you see the feed name and anything under last value or when recorded?
create.jpg
create.jpg (47.88 KiB) Viewed 781 times
If everything is working you should see the block and when holding the button the value changes to 1
button.jpg
button.jpg (12.56 KiB) Viewed 781 times

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”