Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Sketch hangs at the Send command
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.

Sketch hangs at the Send command

by kampto on Fri Mar 04, 2016 9:33 pm

Hi, I have a simple sketch to send the battery voltage of my Feather ESP8266 board to AIO. At the send command the loop hangs up for 30 to 60sec while sending then continues on. Its obvious in the serial monitor because it stops printing during that lengthy send and then continues thru the loop until sending again. Is this normal for the send to hang that long and pause the program? The AIO is receiving the data at these intervals

My Sketch:
Code: Select all | TOGGLE FULL SIZE
#include <ESP8266WiFi.h>
#include "Adafruit_IO_Client.h"
#define AIO_KEY "............................................"
#define ssid  "................"
#define password  "................"
WiFiServer server(80);
WiFiClient client;  // Create an ESP8266 WiFiClient class to connect to the AIO server.
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

void setup() {
  Serial.begin(115200);
  aio.begin();  // Initialize the Adafruit IO client
  server.begin(); Serial.println("Server started");       // Start the server
  delay(50);
  Serial.println();

  // Connect to WiFi network
  WiFi.mode(WIFI_STA);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  IPAddress ip(192, 168, 0, 63);
  IPAddress gateway(192, 168, 0, 1);
  IPAddress subnet(255, 255, 255, 0);
  WiFi.config(ip, gateway, subnet);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  Serial.println(WiFi.localIP());  // Print the IP address
  delay(2000);
}

void loop()
{
  //////////////////////////////////// LiPo Bat Calc ////////////////////////////////
  // read the battery level from the ESP8266 analog in pin.
  int ADC0 = analogRead(A0);
  float volt = ((ADC0 * .00097) * 6.00); // 6=(R2+R1)/R2,  0.00097=1/1023
  float millivolt = (volt * 1000); // convert to millVolts
  int millivolt_int = int(millivolt); // convtert to int cuase Adafruit IO cant do decimals

  ///////////////////////////////////////////// Adafruit aio Feed ////////////////////////////////////

  Adafruit_IO_Feed BatteryVoltage = aio.getFeed("BatteryVoltage"); //  aio.getFeed("BatteryVoltage")

  Serial.println(F("  "));
  Serial.println(F("Start Sending to AIO"));

  BatteryVoltage.send(millivolt_int);  // Send to AIO  *************** SKETCH HANGS AT THIS LINE ******************
  if (BatteryVoltage.send(millivolt_int)) {
    Serial.print(F("Wrote value to feed: "));
  }
  else {
    Serial.println(F("Error writing value to feed!"));
  }

  Serial.println(F("Data Sent to AIO"));
  Serial.println("  ");
  delay(1000);

}



kampto
 
Posts: 99
Joined: Sun Feb 21, 2016 12:51 pm

Re: Sketch hangs at the Send command

by kampto on Sat Mar 05, 2016 3:03 pm

What is meant by example? I have posted the code. Do you need something else? If so I can provide.

kampto
 
Posts: 99
Joined: Sun Feb 21, 2016 12:51 pm

Re: Sketch hangs at the Send command

by kampto on Sat Mar 05, 2016 3:31 pm

By board Settings attached if that helps with the compile
Feather-ESP.png
Feather-ESP.png (12.92 KiB) Viewed 214 times

kampto
 
Posts: 99
Joined: Sun Feb 21, 2016 12:51 pm

Please be positive and constructive with your questions and comments.