i have the esp8266 module working with the arduino mega and they are communicating fine.
I am having issues sending information to thingspeak automatically when i run my code.
what i mean by this is that i am able to send data to thingspeak (thingspeak will display my data correctly) if i manually give the esp8266 AT commands.
e.x
AT+CIPSTART="TCP","184.106.153.149",80
AT+CIPSEND=54
GET /update?key=MYKEYHERE&field1=10
But once my program starts to run, serial monitor/plotter will display my data, but thingpseak isnt receiving anything.
this is the code i have written so far.
Please excuse me if i have not written this post in the correct way, this is my first post ever on here.
#include <SoftwareSerial.h>
#include <stdlib.h>
#define SSID "iPhone"
#define PASS "cristian890"
// Variables
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13; // The on-board Arduion LED
int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550; // Determine which Signal to "count as a beat", and which to ingore.
String GET = "**MYAPIKEY**";
SoftwareSerial ser(9, 10); //RX, TX
// The SetUp Function:
void setup() {
pinMode(LED13, OUTPUT); // pin that will blink to your heartbeat
Serial.begin(9600); // Set's up Serial Communication at certain speed.
ser.begin(9600);
// reset ESP8266
ser.println("AT+RST");
}
// The Main Loop Function
void loop() {
Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's value.
// Assign this value to the "Signal" variable.
Serial.println(Signal); // Send the Signal value to Serial Plotter.
if (Signal > Threshold) { // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
digitalWrite(LED13, HIGH);
} else {
digitalWrite(LED13, LOW); // Else, the sigal must be below "550", so "turn-off" this LED.
}
}
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
delay(2000);
String com = "AT+CWJAP=\"";
com += SSID;
com += "\",\"";
com += PASS;
com += "\"";
//sendDebug(cmd);
delay(5000);
//TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
ser.println(cmd);
if (ser.find("Error")) {
Serial.println("AT+CIPSTART error");
return;
}
// prepare GET string
String getStr = "GET /update?api_key=";
getStr += GET;
getStr += "&field1=";
getStr += String(Signal);
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
ser.println(cmd);
if (ser.find(">")) {
ser.print(getStr);
}
else {
ser.println("AT+CIPCLOSE");
// alert user
Serial.println("AT+CIPCLOSE");
}
}