Hello guys,
I'm rather new, both here and in Arduino niche, and while I do have significant background in programming, some things are just brand new to me, so I need some help from more experienced people.
I have procured some cheap components online, and they work well, the problem I am experiencing is sending data to ThingSpeak. I have created all neccesary accounts and created the channel to my liking, and made the aparatus that I am satisfied with, and which works well without said ThingSpeak. The line ThingSpeak.writeFields just freezes all operations on arduino. Even the extended command with debugging options stays silent.
HW in use:
generic arduino board
MQ2 gas sensor
DHT11 Temp and humidity sensor
ESP8266 WiFi module
Here is the code:
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
#include <DHT.h>
#include <DHT_U.h>
#include <ThingSpeak.h>
#define sensor A0
WiFiClient client;
unsigned long myChannelNumber = ******;
const char* myWriteAPIKey = "****************";
SoftwareSerial ESP8266(8, 9);
unsigned char check_connection = 0;
unsigned char times_check = 0;
DHT dht(7, DHT11);
static const int DHT_SENSOR_PIN = 2;
int gasLevel = 0;
void setup() {
Serial.begin(115200);
ESP8266.begin(115200);
Serial.println("Connecting to Wifi");
while (check_connection == 0) {
Serial.print(".");
ESP8266.print("AT+CWJAP=\"****\",\"****\"\r\n");
ESP8266.setTimeout(5000);
if (ESP8266.find("WIFI CONNECTED\r\n") == 1) {
Serial.println("WIFI CONNECTED");
break;
}
times_check++;
if (times_check > 3) {
times_check = 0;
Serial.println("Trying to Reconnect..");
}
}
ESP8266.print("***VER:");
delay(2000);
ESP8266.println("AT+RST");
delay(1000);
ESP8266.println("AT+GMR");
delay(1000);
ESP8266.println("AT+CWMODE=3");
delay(1000);
ESP8266.println("AT+CWLAP");
delay(1000);
dht.begin();
ThingSpeak.begin(client);
}
void loop() {
Serial.println("Preparation . . .");
ThingSpeak.setField(1, dht.readTemperature());
ThingSpeak.setField(2, dht.readHumidity());
ThingSpeak.setField(3, analogRead(sensor));
Serial.println("Sending . . .");
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Serial.println("Sent . . .");
delay(30000);
}
Serial output is as follows:
Connecting to Wifi
...WIFI CONNECTED
Prepration . . .
Sending . . .
And stuck there for all eternity . . .
Pieces of code have been stolen from all around and reworked to fit my needs, and I know that I might not need all #includes that I have, but that is my secondary issue, and one for after the code starts working properly.