- Sun May 27, 2018 10:09 am
#199299
Hello all.
First time posting on the forum (so apologies if I am not writing in the correct location).
I have recently purchased a sparkfun esp8266 shield to connect to an arduino uno and send some data online (on thingspeak).
I managed to connect the shield & arduino uno to my local wifi, and display analogRead values on the serial monitor. But after loading the sketch on my arduino uno, the memory is ~89% full.
When trying to send data online, only blank data seem to be uploaded to Thingspeak page. I can see the number of entries on the page going up, but no data are actually plotted. I have tried to manually upload a value successfully. It seems more to be an issue with my code and / or shield.
Do any of you have experienced similar memory issues, do you have any recommendation, advice, etc...? I am only starting with Arduino, and am hoping we can find a workaround.
Thanks in advance
Max
PS: My arduino code below.
#include "ThingSpeak.h"
#include <SparkFunESP8266WiFi.h>
#include <SoftwareSerial.h>
char ssid[] = "<VALUE_REMOVED>"; // network SSID (name)
char pass[] = "<VALUE_REMOVED>"; // network password
ESP8266Client client;
unsigned long myChannelNumber = "<VALUE_REMOVED>"; // ThingSpeak Channel No
const char * myWriteAPIKey = "<VALUE_REMOVED>"; // ThingSpeak API Key
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("start loop");
// Verifies that the ESP8266 is operational and connects to WIFI if not currently connected.
initializeESP8266();
ThingSpeak.begin(client);
delay(100);
send_data();
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
Serial.println("wait 20s");
}
void initializeESP8266()
{
int ESP8266_test = esp8266.begin();
for (int i = 0; i < 20; i++)
{
if (ESP8266_test != true) {
delay (500);
Serial.print("ESP8266 not ready... iteration "); Serial.println(i);
} else {
Serial.println("ESP8266 ready!");
connectESP8266();
i=20;
}
}
}
void connectESP8266()
{
// Connect ESP8266 to WIFI if not currently connected.
int retVal = esp8266.status();
if (retVal == 1) {
Serial.println("Already connected to WIFI");
} else {
int retVal2=esp8266.connect(ssid, pass);
for (int j = 0; j < 20; j++)
{
if (retVal2 < 0) {
delay (10000);
Serial.print("Attempting connection to WIFI... iteration "); Serial.print(j); Serial.print(" Status "); Serial.println(retVal2);
} else {
j=20;
Serial.println("Connected to WIFI!");
}
}
}
}
void send_data()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
ThingSpeak.writeField(myChannelNumber, 1, sensorValue, myWriteAPIKey);
if (client.connected()) {client.stop();}
Serial.println("WIFI connection stopped");
}
First time posting on the forum (so apologies if I am not writing in the correct location).
I have recently purchased a sparkfun esp8266 shield to connect to an arduino uno and send some data online (on thingspeak).
I managed to connect the shield & arduino uno to my local wifi, and display analogRead values on the serial monitor. But after loading the sketch on my arduino uno, the memory is ~89% full.
When trying to send data online, only blank data seem to be uploaded to Thingspeak page. I can see the number of entries on the page going up, but no data are actually plotted. I have tried to manually upload a value successfully. It seems more to be an issue with my code and / or shield.
Do any of you have experienced similar memory issues, do you have any recommendation, advice, etc...? I am only starting with Arduino, and am hoping we can find a workaround.
Thanks in advance
Max
PS: My arduino code below.
#include "ThingSpeak.h"
#include <SparkFunESP8266WiFi.h>
#include <SoftwareSerial.h>
char ssid[] = "<VALUE_REMOVED>"; // network SSID (name)
char pass[] = "<VALUE_REMOVED>"; // network password
ESP8266Client client;
unsigned long myChannelNumber = "<VALUE_REMOVED>"; // ThingSpeak Channel No
const char * myWriteAPIKey = "<VALUE_REMOVED>"; // ThingSpeak API Key
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("start loop");
// Verifies that the ESP8266 is operational and connects to WIFI if not currently connected.
initializeESP8266();
ThingSpeak.begin(client);
delay(100);
send_data();
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
Serial.println("wait 20s");
}
void initializeESP8266()
{
int ESP8266_test = esp8266.begin();
for (int i = 0; i < 20; i++)
{
if (ESP8266_test != true) {
delay (500);
Serial.print("ESP8266 not ready... iteration "); Serial.println(i);
} else {
Serial.println("ESP8266 ready!");
connectESP8266();
i=20;
}
}
}
void connectESP8266()
{
// Connect ESP8266 to WIFI if not currently connected.
int retVal = esp8266.status();
if (retVal == 1) {
Serial.println("Already connected to WIFI");
} else {
int retVal2=esp8266.connect(ssid, pass);
for (int j = 0; j < 20; j++)
{
if (retVal2 < 0) {
delay (10000);
Serial.print("Attempting connection to WIFI... iteration "); Serial.print(j); Serial.print(" Status "); Serial.println(retVal2);
} else {
j=20;
Serial.println("Connected to WIFI!");
}
}
}
}
void send_data()
{
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
ThingSpeak.writeField(myChannelNumber, 1, sensorValue, myWriteAPIKey);
if (client.connected()) {client.stop();}
Serial.println("WIFI connection stopped");
}