Arduino Zero with WiFi101 Shield Only Sends Two Updates | Arduino | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Arduino Zero with WiFi101 Shield Only Sends Two Updates
Avatar
wjpavalko

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
1
September 6, 2017 - 8:55 pm
sp_Permalink sp_Print

I have an Arduino Zero with WiFi 101 Shield.  Connected to WiFi and successfully sent data to my channel.  Problem is it only sends two updates, then stops updating. If I reset the Zero, it will send another two (with delay set in sketch).  WiFi light is on and network light glows periodically, so I know the Zero is trying to send the updates, but they don't show up in the channel.

Any ideas?

Avatar
cstapels

Gold
Forum Posts: 83
sp_UserOfflineSmall Offline
2
September 7, 2017 - 10:12 am
sp_Permalink sp_Print

Can you connect the serial monitor and see what responses are being returned by ThingSpeak when you send the data?

Avatar
wjpavalko

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
3
September 7, 2017 - 8:22 pm
sp_Permalink sp_Print

I'm an admitted amateur at this, but can you advise how to print out communications between the Arduino and Thingspeak?  The example WriteVoltage code has no Serial connection. I assume I need to do more than just initialize a serial connection, e.g. add Serial.begin(9600). 

Avatar
wjpavalko

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
4
September 14, 2017 - 9:58 pm
sp_Permalink sp_Print

Any help from anyone else out there?  I tried an MKR1000 board and the same problem occurs.  I get two (not one, not three) updates each time the Arduino is rebooted, and then nothing.  Can't find out how to show communications with either of these boards.

Avatar
cstapels

Gold
Forum Posts: 83
sp_UserOfflineSmall Offline
5
September 15, 2017 - 3:27 pm
sp_Permalink sp_Print

Your ISP connection may be bad.  Try adding a connectWiFi() function and calling it each main loop if there is no connection: 

<put this in loop>

if(WiFi.status() != WL_CONNECTED)
{ connectWifi(); } // Make sure we have an internet connection

 

<put this after the end of your program>

int connectWifi()
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(2500);
Serial.println("Connecting to WiFi"); // Inform the serial output
}
Serial.println("Connected");
ThingSpeak.begin(client);
}

 

You will need Serial.begin(9600) in your setup().

For the thingspeak commands, you can at least test for success:

int success=ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);

Serial.println("success "+String(success));

You can see the serial monitor by pressing ctrl shift m or hitting the plus/curcle icon on the right top of the IDE window.

 

Do you see the number of entries in your channel growing - even if you see no data in your plot?

Avatar
wjpavalko

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
6
September 15, 2017 - 5:16 pm
sp_Permalink sp_Print sp_EditHistory

Thanks.  I put in the code to reconnect the wifi, but it is not executed, so WiFi is connected.

Still, after two updates, I get:

Error code is: -301:ERR_CONNECT_FAILED

Avatar
AugustoEst
Edinburgh
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
7
October 1, 2017 - 4:54 pm
sp_Permalink sp_Print sp_EditHistory

I solved this issue by disconnecting from the WiFi after updating my ThingSpeak channel:

 

void loop()
{
   WiFi.begin(ssid, pass);
   delay(10000); // Waits 10 seconds to confirm connection
   
   // Updates x fields in ThingSpeak

   // Disconnects from the WiFi
   WiFi.disconnect();
 
   // ThingSpeak will only accept updates every 15 seconds
   delay(20000);
}
Avatar
beekeeper

Silver
Forum Posts: 5
sp_UserOfflineSmall Offline
8
October 2, 2017 - 10:17 am
sp_Permalink sp_Print

Hi there,

I have the same toppic but using a MKR 1000 with a TMP36.

For trying I took the example "write voltage" by Thingspeak-library in its newest version 1.3.

My Arduino-IDE-version is 1.8.4

Here is the sketch, a little bit modified after the last entry by AugustoEst:

/*
WriteVoltage

Reads an analog voltage from pin 0, and writes it to a channel on ThingSpeak every 20 seconds.

ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud.

Copyright 2017, The MathWorks, Inc.

Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
See the accompaning licence file for licensing information.
*/

#include "ThingSpeak.h"

// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************

#define USE_WIFI101_SHIELD
//#define USE_ETHERNET_SHIELD

#if defined(ARDUINO_AVR_YUN)
#include "YunClient.h"
YunClient client;
#else
#if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266)
// Use WiFi
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
#else
#include <SPI.h>
#include <WiFi101.h>
#endif
char ssid[] = "***"; // your network SSID (name)
char pass[] = "***"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#elif defined(USE_ETHERNET_SHIELD)
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#endif
#endif

#ifdef ARDUINO_ARCH_AVR
// On Arduino: 0 - 1023 maps to 0 - 5 volts
#define VOLTAGE_MAX 5.0
#define VOLTAGE_MAXCOUNTS 1023.0
#elif ARDUINO_SAMD_MKR1000
// On MKR1000: 0 - 1023 maps to 0 - 3.3 volts
#define VOLTAGE_MAX 3.3
#define VOLTAGE_MAXCOUNTS 1023.0
#elif ARDUINO_SAM_DUE
// On Due: 0 - 1023 maps to 0 - 3.3 volts
#define VOLTAGE_MAX 3.3
#define VOLTAGE_MAXCOUNTS 1023.0
#elif ARDUINO_ARCH_ESP8266
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
#define VOLTAGE_MAX 1.0
#define VOLTAGE_MAXCOUNTS 1023.0
#endif

/*
*****************************************************************************************
**** Visit https://www.thingspeak.com to sign up for a free account and create
**** a channel. The video tutorial http://community.thingspeak.com/tutorials/thingspeak-channels/
**** has more information. You need to change this to your channel, and your write API key
**** IF YOU SHARE YOUR CODE WITH OTHERS, MAKE SURE YOU REMOVE YOUR WRITE API KEY!!
*****************************************************************************************/
unsigned long myChannelNumber = ***;
const char * myWriteAPIKey = "***";

void setup() {

ThingSpeak.begin(client);
}

void loop() {

 

WiFi.begin(ssid, pass);
delay(10000); // Waits 10 seconds to confirm connection

// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading
// On Uno,Mega,YunArduino: 0 - 1023 maps to 0 - 5 volts
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
// On MKR1000,Due: 0 - 4095 maps to 0 - 3.3 volts
float voltage = ((sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS)) - .5 )* 100;

// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.

WiFi.disconnect();

}

 

Everything works fine after uploading the sketch. But when I take the MKR 1000 away from my Mac an I make a restart with a mobile-charging-cable, only 2 updates are sent to Thingspeak. What is wrong???

Thanks fpr helping me

 

Michael 

Avatar
JasonW

Forum Posts: 18
sp_UserOfflineSmall Offline
9
October 2, 2017 - 10:44 am
sp_Permalink sp_Print

I am able to reproduce this behavior.  I'm looking into it.

Avatar
JasonW

Forum Posts: 18
sp_UserOfflineSmall Offline
10
October 2, 2017 - 1:05 pm
sp_Permalink sp_Print

It looks like the latest version of the WiFi101 library has a bug in it.

Until Arduino fixes the bug, a work-around is to downgrade the WiFi101 library to version 13.0.

Avatar
wjpavalko

Silver
Forum Posts: 6
sp_UserOfflineSmall Offline
11
November 4, 2017 - 10:33 pm
sp_Permalink sp_Print

Phew!  I'm happy I wasn't completely incompetent or simply crazy.  😉

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 250

Vinod: 154

cstapels: 83

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

webone

KMVp

aamir786

sugengprayogi

vickysam@gmail.com

farmerkjs

Forum Stats:

Groups: 4

Forums: 17

Topics: 1289

Posts: 4481

 

Member Stats:

Guest Posters: 1

Members: 5652

Moderators: 0

Admins: 2

Administrators: Hans, lee