MKR1000 Plant Communicator Only uploading 2 Data Points | Arduino | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





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

sp_Feed sp_TopicIcon
MKR1000 Plant Communicator Only uploading 2 Data Points
No permission to create posts
March 31, 2018
1:04 am
Avatar
oassali
New Member
Members
Forum Posts: 1
Member Since:
March 31, 2018
sp_UserOfflineSmall Offline

Hello,

I am new to IoT and am currently using the Arduino MKR1000 board. following the "Plant Communicator" project (https://create.arduino.cc/projecthub/arduino/plant-communicator-7ea06f) I am having an issue uploading more than 2 data points to my channel.

I am successfully uploading the first two data points right after uploading my sketch (pasted below) to the board, looking at my serial monitor I can see that the ThingSpeak.writeFields() is still executing but the data is not being sent to my channel. resetting the board or re-uploading the code will send 2 other data points but no more. Could I be losing connection to the thingspeak client somehow, what is a good way to determine if my connection is still fine?

 

#include <WiFi101.h>
#include<WiFiSSLClient.h>
#include "ThingSpeak.h"
const char* ssid = "oassali"; // your network SSID (name)
const char* password = "oMar1331"; // your network password
WiFiClient ThingSpeakClient;
unsigned long myChannelNumber = 463969;
const char* myWriteAPIKey = "U4HV0M9EYTFLHUW4";
int lightPin = A0; //the analog pin the light sensor is connected to
int tempPin = A1; //the analog pin the TMP36's Vout (sense) pin is connected to
int moisturePin = A2;

void setup() {
Serial.begin(9600);
while (!Serial);
delay(2000);
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
while (WiFi.begin(ssid, password) != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
ThingSpeak.begin(ThingSpeakClient);
}

void loop() {
ThingSpeak.setField(1, get_light());
ThingSpeak.setField(2, get_temperature());
ThingSpeak.setField(3, get_average_moisture());
Serial.println(get_light());
Serial.println(get_temperature());
Serial.println(get_average_moisture());
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Serial.println("message sent to cloud");
delay(60000); // send values every 1 minute
}
float get_temperature() {
int reading = analogRead(tempPin);
float voltage = reading * 3.3;
voltage /= 1024.0;
// Print tempeature in Celsius
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
// Convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
return temperatureC;
}
int get_average_moisture() { // make an average of 10 values to be more accurate
int tempValue = 0; // variable to temporarly store moisture value
for (int a = 0; a < 10; a++) {
tempValue += analogRead(moisturePin);
delay(10);
}
return tempValue / 10;
}
int get_light() {
int light_value = analogRead(A0);
return light_value;
}

April 1, 2018
12:35 am
Avatar
rw950431

Top
Members
Forum Posts: 279
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

If you put the line

#define PRINT_DEBUG_MESSAGES

at the top of your code the thingspeak library will print lots of debugging output to the serial monitor- maybe this might help you find whats going on.

April 1, 2018
8:30 pm
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 669
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Getting extra output from the library is a good idea.

  If you think your connection is intermittent, you can put a check on the connection in your main loop.  Have a look at the sonar example in the documentation to see this method.  That example was tested on a MKR1000. 

There may also be an issue with the WiFi  101 library.  Have a look at this thread. You may have to  consider downgrading your wifi101 library version.

February 17, 2019
6:15 pm
Avatar
bradreelgood
New Member
Members
Forum Posts: 2
Member Since:
February 17, 2019
sp_UserOfflineSmall Offline

Hey oassali, were you able to solve this? I'm having the same issue.

Printing the debugging issue there is not much difference between a successful message post and a fail. I'll give downgrading the wifi101 library a shot.

Success
16:53:50.712 -> ts::setField (field: 1 value: "76")
16:53:50.712 -> ts::setField (field: 2 value: "251.76170")
16:53:50.782 -> ts::setField (field: 3 value: "951")
16:53:50.782 -> ts::writeRaw (channelNumber: 705388 writeAPIKey: GXL11IV6CZLKIHD7 postMessage: "field1=76&field2=251.76170&field3=951")
16:53:50.782 -> Connect to default ThingSpeak: api.thingspeak.com:80...Success.
16:53:50.857 -> POST "field1=76&field2=251.76170&field3=951&headers=false"
16:53:52.108 -> Entry ID "10" (10)
16:53:52.108 -> disconnected.

Fail
16:53:52.108 -> message sent to cloud
16:54:50.746 -> ts::setField (field: 1 value: "76")
16:54:50.746 -> ts::setField (field: 2 value: "250.02150")
16:54:50.820 -> ts::setField (field: 3 value: "950")
16:54:50.820 -> ts::writeRaw (channelNumber: 705388 writeAPIKey: GXL11IV6CZLKIHD7 postMessage: "field1=76&field2=250.02150&field3=950")
16:54:50.820 -> Connect to default ThingSpeak: api.thingspeak.com:80...Failed.

February 17, 2019
6:22 pm
Avatar
bradreelgood
New Member
Members
Forum Posts: 2
Member Since:
February 17, 2019
sp_UserOfflineSmall Offline

Okay I can confirm. Downgrading the wifi101 library to 0.14.5 works and successfully posts more than two data points. Thank you rw950431 and cstapels

February 19, 2019
8:28 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 669
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Thanks for confirming, glad to hear you got it working.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
25 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Matthewdupreez1, sbhunu, pabcstar, johnhutcheson1, madhuhada, dayne

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457