0

Send Arduino data to IO.Adafruit with ESP8266
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Send Arduino data to IO.Adafruit with ESP8266

by Morane on Sun Aug 06, 2017 10:13 pm

Hi,

I'm new with Arduino and my project is working well. Now I need
to send that information to IO Adafruit with an ESP8266.

All examples I found used the ESP8266 to read the sensors and
send the result but I just want to used the ESP8266 as a wifi
transmitter.

Since my project is already working with an Arduino UNO, I now want
to send the information from all my sensors to IO.Adafruit.

Anybody have an idea on how to do that ?

Also, reading my sensors results to an iPhone via Bluetooth
would be very interesting.

Morane
 
Posts: 4
Joined: Sun Aug 06, 2017 9:59 pm

Re: Send Arduino data to IO.Adafruit with ESP8266

by RH3 on Tue Aug 08, 2017 3:14 am

If I understand your correctly your UNO reads the sensor data but you only want to use the ESP8266 to act as the WiFi interface.

In that case probably the easiest option is to use serial communication between the UNO and the ESP8266. But... you'll need the ESP8266 to do some processing and the ESP2866 Huzzah is perfect for just that.

Setup your UNO to push its sensor data via the serial port to your ESP2866. You may need to create some form of protocol to define the difference between temperature/humidity data such as 'temp=25.3,humid=80' etc.

Follow the instructions to set up the ESP8266 to connect to your WiFi network, and in the sketch loop() read from the serial port and break the incoming data into the temperature and humidity values and save them to a couple of variables. Then in a timed loop, say every minute, connect to Adafruit.io, read the variable and construct the MQTT message to send to Adafruit.io

The ESP8266 Huzzah Breakout is faster (and cheaper) than a UNO and it would be simpler to use it to read and process the sensor data directly.

Hope this gets you on the way.

Richard.

RH3
 
Posts: 34
Joined: Sun Aug 03, 2014 4:22 am

Re: Send Arduino data to IO.Adafruit with ESP8266

by Morane on Tue Aug 08, 2017 9:01 am

I looked at the Huzzah pinout and I don't think it can support my project.

I have 4 buttons and probably need to add another one.
4 relays output and may add a fifth one soon,
2 lcd display (i2c)
one sensor analog input
2 ads1115

My project is already built and working, if you look at the picture you will see
that rebuilting a new one is not an option. Adding a circuit to transmit the
data from the existing arduino is what I was thingking about.

IMG_9463.JPG
IMG_9463.JPG (162.92 KiB) Viewed 634 times


IMG_9489.JPG
IMG_9489.JPG (99.15 KiB) Viewed 633 times

Morane
 
Posts: 4
Joined: Sun Aug 06, 2017 9:59 pm

Re: Send Arduino data to IO.Adafruit with ESP8266

by Mortal517 on Tue Aug 08, 2017 2:06 pm

Hi, I'm having a similar question. I have a already built project and needing something to upload data from the arduino to the internet. Probably needing something to work as a simple web server to be able to just display a line of numbers. Did you eventually find a solution?

Mortal517
 
Posts: 6
Joined: Mon May 15, 2017 1:34 pm

Re: Send Arduino data to IO.Adafruit with ESP8266

by Morane on Tue Aug 08, 2017 2:40 pm

No, not yet.

I'm searching how to send from Arduino "serial" to the ESP8266
and I will have to do a separate code for the ESP8266 to connecte
the internet and send the information using MQTT to Adafruit IO dashboard.

Still looking and reading now..

Morane
 
Posts: 4
Joined: Sun Aug 06, 2017 9:59 pm

Re: Send Arduino data to IO.Adafruit with ESP8266

by jwcooper on Tue Aug 08, 2017 3:11 pm

Check out some examples here, they might get you close to what you want to do:
https://github.com/adafruit/Adafruit_IO ... r/examples

jwcooper
 
Posts: 663
Joined: Tue May 01, 2012 9:08 pm

Re: Send Arduino data to IO.Adafruit with ESP8266

by DoBoter on Tue Aug 22, 2017 4:40 am

Hi, I have it working with a Nano, Uno and Mega connected to an ESP8266, version 01 and 12E.

Look at the post
Arduino MEGA + ESP8266-01 IO wont compile


I hope this might help,
I have also got it working with a DHT22 temperature/humidity sensor

Code: Select all | TOGGLE FULL SIZE
 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.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
 
#include "WiFiEsp.h"  // You need this library installed
#include "WifiEspClient.h"
#include "Adafruit_MQTT.h"  // As well as these...
#include "Adafruit_MQTT_Client.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1  //  The Mega will use Hardware Serial1, Uno uses Software Serial1
#include "SoftwareSerial.h"  //
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
/************************* WiFi Access Point *********************************/

char ssid[] = "Network name";            // your network SSID (name)
char pass[] = "password";        // your network password
int status = WL_IDLE_STATUS;

RingBuffer buf(8); // Code from another sketch, makes it run faster/ smoother. I'm not sure if it helps

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

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT   1883
#define AIO_USERNAME    "Username" // Put your user name here
#define AIO_KEY         "Very long key code here" // Put your long key code here

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

WiFiEspClient client; 

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

/****************************** Feeds ***************************************/

// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");

//  ---> CHANGED FROM ORIGINAL (delated listening to feed)<---

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

// Bug workaround for Arduino 1.6.6, it seems to need a function declaration
// for some reason (only affects ESP8266, likely an arduino-builder bug).

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600); 
  WiFi.init(&Serial1); 
  delay(10);

  Serial.println(F("Adafruit MQTT demo"));

  // Connect to WiFi access point.
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

   // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
   
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
 // printWifiStatus();
 
  // start the web server on port 80
//  server.begin();
}

uint32_t x=0;

void loop() {
  // 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.
  MQTT_connect();

  // this is our 'wait for incoming subscription packets' busy subloop
  // try to spend your time here



  // Now we can publish stuff!
  Serial.print(F("\nSending photocell val "));
  Serial.print(x);
  Serial.print("...");
  if (! photocell.publish(x++)) {
    Serial.println(F("Failed"));
  } else {
    Serial.println(F("OK!"));
    delay(10000);
  }

  // ping the server to keep the mqtt connection alive
  // NOT required if you are publishing once every KEEPALIVE seconds
  /*
  if(! mqtt.ping()) {
    mqtt.disconnect();
  }
  */
}

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

  uint8_t retries = 3;
  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
       retries--;
       if (retries == 0) {
         // basically die and wait for WDT to reset me
         while (1);
       }
  }
  Serial.println("MQTT Connected!");
}


DoBoter

DoBoter
 
Posts: 6
Joined: Sun Feb 26, 2017 3:40 am

Re: Send Arduino data to IO.Adafruit with ESP8266

by btreichel on Wed Nov 08, 2017 2:24 pm

Am I correct in thinking that if I use software serial "SoftwareSerial Serial1(6, 7); // RX, TX" that this will allow me to keep the ide's serial monitor capability?

Thanks, Ben

btreichel
 
Posts: 79
Joined: Tue Jul 25, 2017 3:00 pm

Please be positive and constructive with your questions and comments.