0

Feather ESP8266 WifiClient used in tandem with Adafruit IO
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather ESP8266 WifiClient used in tandem with Adafruit IO

by martian on Thu Jul 12, 2018 12:01 am

Hi!

I am working on ambitious (for me) Arduino sketch and have hit a wall. I have a lot of it worked out but can't figure out the last step.

I'm combining (all working) examples of 3 separate sketches to create a garage door opener and door status monitor:

1) Adafruit IO - used to send a button status connected to the ESP (on or off with a reed switch, indicates if the door is open)

2) Feather Relay that is triggered through browser logged into my own password protected webserver running on the ESP8266 feather.

3) IFTTT triggers, relying on WiFiClientSecure client instance to GET/POST urls that trigger notifications of door status sent to my phone through their app.

So, the short of it is the ESP will reset/reboot every time I try and send an IFTTT trigger, but NOT if I strip out the adafruit IO code. Conversely, the opposite is true.

The serial monitor reports ESP8266 exception 29, plus a super long string of nonsense.

Some research leads me to suspect that the problem is the "code tried to write to a protected area in memory" which I think might be due to ESP not being able to handle more than one client instance while running the server.

I believe/assume adafruit IO is creating a client which conflicts with the client that I am creating when this function runs (on door status button push/release):

Code: Select all | TOGGLE FULL SIZE
void MessageSend(int choice) {
  WiFiClientSecure client;
  if (!client.connect(host, httpsPort)) {
  Serial.println("connection failed");
  return;
  }
  Serial.print("requesting URL: ");
  client.print(String("GET ") + url[choice] + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\r\n" +
               "Connection: close\r\n\r\n");
  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('\n');
  Serial.println("reply was:");
  Serial.println("==========");
  Serial.println(line);
  Serial.println("==========");
  Serial.println("closing connection");
  Serial.println("Message Sent");   
  }


Is there a way to make calls on the adafruit IO client that I can implement in the above code to avoid creating this additional client instance? The example AIO code I have looked through seems only geared to interact with AI specifically and not follow the the typical WifiClient conventions.

Any alternate suggestion as to the cause are appreciated as well.

Thanks!

martian
 
Posts: 77
Joined: Wed Sep 27, 2017 2:17 am

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by brubell on Thu Jul 12, 2018 10:20 am

The serial monitor reports ESP8266 exception 29, plus a super long string of nonsense.


You might have some luck with the EspExceptionDecoder, it can print out more verbose messages: https://github.com/me-no-dev/EspExceptionDecoder


I believe/assume adafruit IO is creating a client which conflicts with the client that I am creating when this function runs (on door status button push/release):


If you're using the Adafruit IO Arduino library, the client is created by a call to io.connect(), subscribes to a feed by feed->get(), and data is processed by io.run().

brubell
 
Posts: 166
Joined: Fri Jul 17, 2015 10:33 pm

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by martian on Thu Jul 12, 2018 11:52 pm

Thank you. The exception decoder looks interesting, but looking at the examples of output it provides, I’m not sure how much more meaningful it would be to me.

I’m feeling confident of my diagnosis that the two clients can’t play nice together, based on watching my serial monitor as it happens, so I’m focusing on how to make the one client do the other’s job.

Since the Adafruit IO library is necessary for the interaction with your service, I’m trying to work out how to get the client created with your library to make connections to non-Adafruit websites.

Can io.connect or feed->get() be used to make a connection to another URL in some way like my posted code? To be clear, the concatenation above results in something along the lines of:

https://maker.ifttt.com/trigger/EventNa ... retkey.....

martian
 
Posts: 77
Joined: Wed Sep 27, 2017 2:17 am

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by brubell on Fri Jul 13, 2018 11:16 am

Since the Adafruit IO library is necessary for the interaction with your service, I’m trying to work out how to get the client created with your library to make connections to non-Adafruit websites.


We have integrations for both IFTTT (https://learn.adafruit.com/using-ifttt-with-adafruit-io) and Zapier (https://learn.adafruit.com/using-zapier ... dafruit-io).

brubell
 
Posts: 166
Joined: Fri Jul 17, 2015 10:33 pm

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by martian on Fri Jul 13, 2018 2:22 pm

Thanks again.

I tried using Adafruit io integration with IFTTT at the beginning, but found it to be unreliable and only got notifications intermittently. When I connected directly to IFTTT it works every time.

If there is not a way to connect to a url with the AIO client, Is there a way to turn it off or disconnect temporarily within the sketch?

martian
 
Posts: 77
Joined: Wed Sep 27, 2017 2:17 am

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by KenMazing on Fri Jul 13, 2018 3:37 pm

I've just started in this field, but to me it looks like one could use the tutorial at https://learn.adafruit.com/stream-iphone-ios-sensor-data-to-adafruit-io/sending-data-with-rest-post-method to learn how to do a raw post to the adafruit site, thereby eliminating the need for adafruitio library.

I'll be looking into that this weekend.

Ken

KenMazing
 
Posts: 5
Joined: Sun Jan 21, 2018 11:35 am

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by brubell on Fri Jul 13, 2018 3:47 pm

Good luck! If you have any questions after the weekend, feel free to ask.

brubell
 
Posts: 166
Joined: Fri Jul 17, 2015 10:33 pm

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by martian on Fri Jul 13, 2018 10:59 pm

KenMazing wrote:do a raw post to the adafruit site, thereby eliminating the need for adafruitio library.


This is sort of the opposite of what I am looking for, though if I could get the job done, that'd be fine. I think the code is a bit beyond me still. I'd prefer to keep the AIO library and figure out how to load an outside URL, since IFTTT simply requires visiting a URL to trigger the notification.

I pasted this URL (with my info) in a browser and it seems to return the full data record:

https://io.adafruit.com/api/feeds/your- ... O-Key-Here

Several hundred records like this one of pressing a button:

[{"id":"0DXNWEEMQW2CJCF5Y8E8ZHYSRK","feed_id":836019,"value":"1","location":{"lat":"0.0","lon":"0.0","ele":"0.0"},"created_at":"2018-07-12T01:24:43Z","updated_at":"2018-07-12T01:24:43Z","expiration":"1533950683.0","lat":"0.0","lon":"0.0","ele":"0.0"},

What I need to do is send a value to my feed.

martian
 
Posts: 77
Joined: Wed Sep 27, 2017 2:17 am

Re: Feather ESP8266 WifiClient used in tandem with Adafruit

by KenMazing on Sun Aug 05, 2018 5:13 pm

Well, I have been trying this for much of a weekend now. I have been able to connect and post data to adafruitio using curl, and using javascript/jquery no problem.

Using esp8266wifi.h and wificlientsecure.h, I finally got a secure connection to io.adafruit.com. But I couldn't get the certificate to verify. I also couldn't perform a get. I haven't tried too hard, because it took me long enough to get to this point.

I will try more later, or I may punt and go back to using the adafruit library and see if I can make it work with the server given some info I got in another thread.

Ken

KenMazing
 
Posts: 5
Joined: Sun Jan 21, 2018 11:35 am

Please be positive and constructive with your questions and comments.