So I have tried to connect this program to Thing Speak for the last several days. I had someone else try it and I was told it worked correctly but yet no matter how many times I try it just does not do what it is set up to do . I purposely left out the credentials , It does compile but does not display correctly on serial monitor. I have tried several baud rates but still the same problem. What happens is that it shows connecting to my Netgear but then all I get is a bunch of ............. I am trying to send data to Thing Speak and display the wind speed on a graph .I have the information saved on the site to display but if I can't see it on my monitor, i can'texpect it will populate Thing Speak . The program is basically Davis Wind Speed . Any help would be appreciated, Also a second program which is the original I was adapting to,which by the way works on the serial monitor.
#include <ESP8266WiFi.h>
#include "secrets.h"
#include <math.h>
#define WindSensorPin 4 // The pin location of the anemometer sensor
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // speed miles per hour
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
char ssid[] = "YOUR SSID"; // your network SSID (name)
char pass[] = "YOUR PASS"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
unsigned myChannelNumber = 1172766;
const char * myWriteAPIKey = "API_KEY";
bool incrementRotation = false;
// This is the function that the interrupt calls to increment the rotation count
ICACHE_RAM_ATTR void isr_rotation () {
incrementRotation = true;
Serial.print("ISR");
}
void setup() {
Serial.begin(115200); // Initialize serial
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
//pinMode(WindSensorPin,INPUT);
//attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
// Serial.println("Rotations\tMPH"); //use for debug
void loop() {
// Connect or reconnect to WiFi
if (WiFi.status() != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
Rotations = 0; // Set Rotations count to 0 ready for calculations
//sei(); // Enables interrupts
//delay (3000); // Wait 3 seconds to average
//cli(); // Disable interrupts
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75
if (incrementRotation) {
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
// 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.
WindSpeed = Rotations * 0.75;
int x = ThingSpeak.writeField(myChannelNumber, 1, WindSpeed, myWriteAPIKey);
if (x == 200) {
Serial.println("Channel update successful.");
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
incrementRotation = false;
}
}
}
}Type or paste code here
Working but not connected to Thing Speak
#define WindSensorPin (2) // The pin location of the anemometer sensor
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // speed miles per hour
void setup() {
Serial.begin(9600);
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
Serial.println("Davis Wind Speed Test");
Serial.println("Rotations\tMPH");
}
void loop() {
Rotations = 0; // Set Rotations count to 0 ready for calculations
sei(); // Enables interrupts
delay (3000); // Wait 3 seconds to average
cli(); // Disable interrupts
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75
WindSpeed = Rotations * 0.75;
Serial.print(Rotations); Serial.print("\t\t");
Serial.println(WindSpeed);
}
// This is the function that the interrupt calls to increment the rotation count
void isr_rotation () {
if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
Rotations++;
ContactBounceTime = millis();
}
}
Preformatted text`