0

M0 Feather with WINC1500 and IoT!
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.

M0 Feather with WINC1500 and IoT!

by Seekatar on Tue Apr 19, 2016 8:10 pm

I won the M0 IoT kit at Microsoft's //Build conference a few weeks ago and have been playing with it. Downloading the Adafruit IoT code, I didn't see the WINC1500 supported, so I ported Adafruit_IO_CC3000.h and the ino sample to work with the WINC1500 on the M0 feather and it's working like a champ, posting to adafruit.io!

I'm new to the Pi/Arduino realm, and Adafruit is a great resource. Keep up the great work.

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Wed Apr 20, 2016 7:50 am

Did you manage to subscribe too or only to publish to AdafruitIO?

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Wed Apr 20, 2016 9:33 am

The CC3300 sample I ported does both directions and it works posting a value to the IoT service and getting it back. I'll put the source on GitHub today.

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Wed Apr 20, 2016 11:01 am

Thank you so much, can't wait to take a look at your code.
I have WINC1500 Breakout Board and it looks impossible to subscribe using the code in MQTT Example by Adafruit (I'm not the only one with this problem).

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Wed Apr 20, 2016 8:18 pm

testFeed.receive() works on the Welcome Feed in the sample (for me)

I updated GitHub https://github.com/Seekatar/GpioPlaygro ... r/WINC1500

Copy Adafruit_IO_WINC1500.h to your libraries/Adafruit_IO_Adafruit folder, on Windows this is C:\Users\<username>\Documents\Arduino\libraries\Adafruit_IO_Arduino\Adafruit_IO_WINC1500.h

For the sample, create a my_keys.h for your keys as the comment in the WINC1500.ino says to avoid putting secrets in a file you may commit.

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Thu Apr 21, 2016 6:23 am

Hello Seekatar,
I tried your code but with no luck.
Here's serial output
Adafruit IO winc1500 test!

Attempting to connect to Marso_Wi-Fi...Attempting to connect to SSID: Marso_Wi-Fi
Connected!
Ready!
Error writing value to feed!
Waiting 10 seconds and then reading the feed value.
Received value from feed:
Waiting 10 seconds and then writing a new feed value.
Error writing value to feed!


And here's the code:
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_WINC1500.h>
#include <SPI.h>
// #include "utility/debug.h"
#include "Adafruit_IO_WINC1500.h"


// Configure WiFi access point details.
#define WLAN_SSID       "Marso_Wi-Fi"  // can't be longer than 32 characters!
#define WLAN_PASS       "my_pass"

// Configure Adafruit IO access.
#define AIO_KEY    "my_AIO_key"

// #include "my_keys.h"

// Configure WINC1500 pins.
// guide you don't need to modify these:
#define WINC_CS   8
#define WINC_IRQ  7
#define WINC_RST  4
// #define WINC_EN   2     // or, tie EN to VCC and comment this out
// The SPI pins of the WINC1500 (SCK, MOSI, MISO) should be
// connected to the hardware SPI port of the Arduino.
// On an Uno or compatible these are SCK = #13, MISO = #12, MOSI = #11.
// On an Arduino Zero use the 6-pin ICSP header, see:
//   https://www.arduino.cc/en/Reference/SPI
// Setup the WINC1500 connection with the pins above and the default hardware SPI.
Adafruit_WINC1500 WiFi(WINC_CS, WINC_IRQ, WINC_RST);

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WINC1500 object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_WINC1500 aio = Adafruit_IO_WINC1500(WiFi, AIO_KEY );

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_WINC1500 object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed testFeed = aio.getFeed("my_username/feeds/my_feed");

// Global state to increment a number and send it to the feed.
unsigned int count = 0;

#define halt(s) { while(true) { Serial.println(F( s )); delay(1000); }  }

void setup() {
  // Setup serial port access.
  Serial.begin(9600);

  Serial.println(F("Adafruit IO winc1500 test!"));

  // Attempt to connect to an access point.
  Serial.print(F("\nAttempting to connect to "));
  Serial.print(WLAN_SSID); Serial.print(F("..."));

  // attempt to connect to Wifi network:
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(WLAN_SSID);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    WiFi.begin(WLAN_SSID, WLAN_PASS);

    // wait 10 seconds for connection:
    uint8_t timeout = 10;
    while (timeout && (WiFi.status() != WL_CONNECTED)) {
      timeout--;
      delay(1000);
    }
  } 
  Serial.println(F("Connected!"));

  // Initialize the Adafruit IO client class (not strictly necessary with the
  // client class, but good practice).
  aio.begin();

  Serial.println(F("Ready!"));
}

void loop() {
  // Increment the count value and write it to the feed.
  count += 1;
  // To write a value just call the feed's send function and pass it the value.
  // Send will create the feed on Adafruit IO if it doesn't already exist and
  // then add the value to it.  Send returns a boolean that's true if it works
  // and false if it fails for some reason.
  if (testFeed.send(count)) {
    Serial.print(F("Wrote value to feed: ")); Serial.println(count, DEC);
  }
  else {
    Serial.println(F("Error writing value to feed!"));
  }

  // Now wait 10 seconds and read the current feed value.
  Serial.println(F("Waiting 10 seconds and then reading the feed value."));
  Serial.flush(); // if no console hangs
  delay(10000);

  // To read the latest feed value call the receive function on the feed.
  // The returned object will be a FeedData instance and you can check if it's
  // valid (i.e. was successfully read) by calling isValid(), and then get the
  // value either as a text value, or converted to an int, float, etc.
  FeedData latest = testFeed.receive();
  if (latest.isValid()) {
    Serial.print(F("Received value from feed: ")); Serial.println(latest);
    // By default the received feed data item has a string value, however you
    // can use the following functions to attempt to convert it to a numeric
    // value like an int or float.  Each function returns a boolean that indicates
    // if the conversion succeeded, and takes as a parameter by reference the
    // output value.
    int i;
    if (latest.intValue(&i)) {
      Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
    }
    // Other functions that you can use include:
    //  latest.uintValue() (unsigned int)
    //  latest.longValue() (long)
    //  latest.ulongValue() (unsigned long)
    //  latest.floatValue() (float)
    //  latest.doubleValue() (double)
  }
  else {
    Serial.print(F("Failed to receive the latest feed value!"));
  }

  // Now wait 10 more seconds and repeat.
  Serial.println(F("Waiting 10 seconds and then writing a new feed value."));
  Serial.flush();
  delay(10000);
 
}

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Thu Apr 21, 2016 6:45 am

Is you AdaFruit IoT key correct, and the feed name correct? Even though the doc says you can post to name, key, or id for a feed, I found only the name would work and if it has spaces, those must be encoded. E.g. "Welcome%20Feed" I made that sample look like the CC3000, which doesn't have much in the way of feedback. If you still have issues, I'll add more output regarding failure.

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Thu Apr 21, 2016 6:59 am

Everything is 100% correct since I copy pasted things from a script which can actually send info to AdafruitIO.

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Thu Apr 21, 2016 7:47 am

Ok. I'll take a look after work today. I'm using the Feather with the WINC1500 onboard not the breakout, but since you're connecting to WiFi, it looks like that's ok. If you have other electronics attached, I'd remove them to make the problem simpler. I had problems with the OLED wing conflicting, until I realized its initialization does a reset by default.

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Thu Apr 21, 2016 9:15 am

Only the beakout is connected and since they share the same library I don't think that there are any big differences between the breakout and the Feather.
Thank you so much for your help

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Thu Apr 21, 2016 6:17 pm

I see you removed a few things from the file. For me I had to have WINC_EN defined. And is "my_username/feeds/my_feed" really the name of your feed?

I'm using the WINC1500.ino exactly as I have it on GitHub and it works for me (fwiw).

Try putting this at the very top of the ino, then you'll get more details about the error in the serial output from the WINC1500 code from Adafruit. I used a wrong key and it gave the the HTTP result instead of the vanilla error.

#define ADAFRUIT_IO_DEBUG

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Re: M0 Feather with WINC1500 and IoT!

by marso on Wed Apr 27, 2016 5:27 am

Hello,
Sorry for my late answer I've been really busy at work I will give a try to your solution and will let you know asap.

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by marso on Fri Apr 29, 2016 10:08 am

About feed name: "my_username/feeds/my_feed"
I based that on adafruit's tutorial as you can see here
https://learn.adafruit.com/adafruit-io/mqtt-api

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by marso on Fri Apr 29, 2016 10:14 am

Here's my new log
Adafruit IO winc1500 test!

Attempting to connect to Marso_Wi-Fi...Attempting to connect to SSID: Marso_Wi-Fi
Connected!
Ready!
HTTP POST failed with error code: 302
Error writing value to feed!
Waiting 10 seconds and then reading the feed value.
Failed to connect to service!
Received value from feed:
Waiting 10 seconds and then writing a new feed value.
Failed to connect to service!
Error writing value to feed!
Waiting 10 seconds and then reading the feed value.
Failed to connect to service!
Received value from feed:
Waiting 10 seconds and then writing a new feed value.
Failed to connect to service!
Error writing value to feed!
Waiting 10 seconds and then reading the feed value.
Failed to connect to service!
Received value from feed:
Waiting 10 seconds and then writing a new feed value.

marso
 
Posts: 20
Joined: Wed Feb 19, 2014 6:06 am

Re: M0 Feather with WINC1500 and IoT!

by Seekatar on Fri Apr 29, 2016 1:31 pm

You got a Http 302. https://en.wikipedia.org/wiki/HTTP_302

They changed the API last week https://io.adafruit.com/blog/ They say you need to change the url, but it worked for me as of last night. Try making the changes from the blog and make sure you can post with something else. (I use PowerShell on Windows)

Seekatar
 
Posts: 10
Joined: Wed Mar 09, 2016 9:10 pm

Please be positive and constructive with your questions and comments.