Random appearance of error code 400

7 views (last 30 days)
Error code 400 randomly occurs. Sometimes for long periods the acquisition on two channels works fine, sometimes no. The last case occurred on April 30, 2020 at 20:50:20 GMT+2 and continuing while I am writing (May 1st 07:40 GMT+2). All times this occurred I checked my Wi-Fi router and no problem was found. The acquisition interval for both channels is 120 s.
I suspect that for some reasons your server stops working and the problem is not in my software. Thank you.
P.S.
At 7:47:41 GMT+2, May 1st the acquisition started again without any action done.

Accepted Answer

Daniele Gozzi
Daniele Gozzi on 1 May 2020
Thank you for your kind response. Give me, please, instructions as to track the exact request my code is making. At present, the unique thing I can track is the error code of unsuccessful connection (400). Many thanks
  1 Comment
Vinod
Vinod on 1 May 2020
Can you put your code on GitHub and post a link here?

Sign in to comment.

More Answers (1)

Vinod
Vinod on 1 May 2020
Edited: Vinod on 1 May 2020
A 400 response is in response to a bad request. This usually can be traced back to a request that likely has badly encoded data. Likely in certain sensor values, the data isn't encoded correctly. The best way to track down the issue is to log the exact request your code is making and inspect that.
We have tens of thousands of devices sending data to ThingSpeak at any given time and we monitor for systemic issues 24x7x365. If there was a server side issue, we would likely know about and resolve it before most people notice.
  2 Comments
Daniele Gozzi
Daniele Gozzi on 1 May 2020
Edited: Vinod on 3 May 2020
//I commenti che iniziano con "&&&" si riferiscono alla cancellazione di line sul monitor
#include <WiFi.h> // Built-in
#include <time.h> // Built-in
#include <ESP32_Servo.h>// https://github.com/jkb-git/ESP32Servo
/*
Up to 4 INA 219 boards may be connected. Addressing is as follows:
Board 0: Address = 0x40 Offset = binary 00000 (no jumpers required)
Board 1: Address = 0x41 Offset = binary 00001 (bridge A0 as in the photo above)
Board 2: Address = 0x44 Offset = binary 00100 (bridge A1)
Board 3: Address = 0x45 Offset = binary 00101 (bridge A0 & A1)
Board GY-271
Board 4: Address = 0x0D
*/
#include <Wire.h>
#include <Adafruit_INA219.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <QMC5883LCompass.h>
QMC5883LCompass compass;
Adafruit_INA219 ina219_Bat;
Adafruit_INA219 ina219_SP(0x41);
Adafruit_INA219 ina219_Servo(0x44);
#include <ThingSpeak.h>
#include "secrets.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
// Initialize our values
float pressure; //pressione misurata in hPa
float temperature;
int altitude;
int altitude0 = 49; //quota in m dove è situato il sensore BME280
float humidity;
float p0;//sealevel pressure hPa
float azi;
float rho;
float teta;
float phi;
float Zvalue;
#define SECRET_CH_ID 616359 // replace 0000000 with your channel number (Meteo)
#define SECRET_WRITE_APIKEY_1 "XYZ1" //Meteo
#define SECRET_CH_ID 612947 // replace 0000000 with your channel number (Sun Tracker)
#define SECRET_WRITE_APIKEY_0 "XYZ0"// replace XYZ with your channel write API Key_Sun Tracker
WiFiClient client;
unsigned long myChNo1 = 616359;
unsigned long myChNo0 = 612947;
const char * myWriteAPIKey0 = "XYZ0";
const char * myWriteAPIKey1 = "XYZ1";
String myStatus0 = "";
String myStatus1 = "";
//Analog inputs
double kf= 3300.000/4095;//3300/4095 fattore di conversione per analog read in Volt
//Rete Vodafone Porto Ercole
//const char* ssid = "Vodafone-SSID";
//const char* password = "REDACTED";
//Rete Infostrada Roma con extender su balcone
const char* ssid = "Edimax Repeater";
const char* password = "REDACTED";
//const char* ssid = "Infostrada-2.4GHz-6FC4AA";
//const char* password = "3749509360778710";
double Lon = 12.5125 * DEG_TO_RAD,
Lat = 41.9361111 * DEG_TO_RAD,
elevation,
azimuth;// Lon < 0 -->W
double elecorr,azicorr;
double tt;//time of a day in fractional hour
#define elevation_servo 19
#define azimuth_servo 18
#define DEG_TO_RAD 0.0174532925//pi/180
float sun_azimuth;
float sun_elevation;
// Published values for SG90 servos; adjust if needed
int minUs = 250;
int maxUs = 2750;
String time_str, current_hour, current_minute, current_day, current_month, current_year;
Servo Azi_servo;
Servo Ele_servo;
//Set relay output
const int rel = 15;//GPIO 15
//LED readings
const int ledPin = 13;
//analog input LDRs
int LDRRPin = 39; // Pin SN_select the input pin for Rear LDR
float LDRR; // variable to store the value coming from Rear LDR
int LDRFPin = 36; // Pin SP_select the input pin for Front LDR
float LDRF; // variable to store the value coming from Front LDR
int LDRmax = 3303; //LDRs max value in mV
//INA219
float shuntvoltageSP;
float busvoltageSP;
float currentSP_mA;
float powerSP_mW;
float loadvoltageSP;
float shuntvoltageBat;
float busvoltageBat;
float currentBat_mA;
float powerBat_mW;
float loadvoltageBat;
float shuntvoltageServo;
float busvoltageServo;
float currentServo_mA;
float powerServo_mW;
float loadvoltageServo;
float Ratiopower; //Ratio SPpower/Batpower
void setup() {
Serial.begin(115200);
StartWiFi(ssid, password);
compass.init();
/*
* call setSmoothing(STEPS, ADVANCED);
*
* STEPS = int The number of steps to smooth the results by. Valid 1 to 10.
* Higher steps equals more smoothing but longer process time.
*
* ADVANCED = bool Turn advanced smmothing on or off. True will remove the max and min values from each step and then process as normal.
* Turning this feature on will results in even more smoothing but will take longer to process.
*
*/
compass.setSmoothing(10,true);
pinMode(ledPin, OUTPUT);//LED reading
pinMode(rel, OUTPUT);// relay to switch ON/OFF servos
//BME sensor
Serial.begin(115200);
Serial.println(F("BME280 test"));
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
{
Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
}
uint32_t currentFrequency;
Serial.println("Hello!");
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219_SP.begin(); // Initialize first board (default address 0x40)
ina219_Bat.begin(); // Initialize second board with the address 0x41
ina219_Servo.begin(); // Initialize second board with the address 0x44
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
ina219_SP.setCalibration_16V_400mA();
ina219_Bat.setCalibration_16V_400mA();
ina219_Servo.setCalibration_16V_400mA();
Serial.println("Measuring voltage and current with INA219 ...");
}
StartTime();
UpdateLocalTime();
Azi_servo.attach(azimuth_servo,minUs,maxUs);
Ele_servo.attach(elevation_servo,minUs,maxUs);
test_azimuth();
delay(1000);
test_elevation(); // Stop at 85 which is vertical or 0 elevation
delay(1000);
digitalWrite(rel, HIGH);//Initialize relay status OFF
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak
}
void loop() {
//Turn ledPin ON
digitalWrite(ledPin, HIGH);
// All time values must not be in DST, Day Save Time (ora legale)
UpdateLocalTime();
Serial.println(Update_DateTime());
Calculate_Sun_Position(current_hour.toInt(), current_minute.toInt(), 0, current_day.toInt(), current_month.toInt(), current_year.toInt()); // parameters are HH:MM:SS DD:MM:YY start from midnight and work out all 24 hour positions.
Azi_servo.write(map(sun_azimuth, 90, 270, 180, 0));// Align to azimuth_map(value, fromLow, fromHigh, toLow, toHigh)
if (sun_elevation < 0) {
sun_elevation = 0; // Point at horizon if less than horizon_sunset
digitalWrite(rel, HIGH); //Power supply DC-DC OFF_no more 5V
}
else{
sun_elevation > 0; //Sunrise
digitalWrite(rel, LOW);// Power supply DC-DC ON_ 5V established
}
Ele_servo.write(85-sun_elevation); // il pannello non può arrivare esattamente verticale a 90°
reading_sensor(); //Go to the routine
//Turn ledPin OFF
digitalWrite(ledPin, LOW);
delay(74 * 1000); // Wait 74s about_the computing time is 46s_60s about for each point_120 s pointj
}
void Calculate_Sun_Position(int hour, int minute, int second, int day, int month, int year) {
double JDate, T, JD_frac, L0, M, e, C, L_true, f, R, GrHrAngle, Obl, RA, Decl, HrAngle;
long JDx;
int zone = 0;
int DST = 2; //If = 2 DST is in progress otherwise DST= 0
JDate = JulianDate(year, month, day);
JD_frac = ((hour-DST) + minute / 60. + second / 3600.0) / 24.0 - 0.5;
T = JDate - 2451545; T = (T + JD_frac) / 36525.0;
L0 = DEG_TO_RAD * fmod(280.46645 + 36000.76983 * T, 360);
M = DEG_TO_RAD * fmod(357.5291 + 35999.0503 * T, 360);
e = 0.016708617 - 0.000042037 * T;
C = DEG_TO_RAD * ((1.9146 - 0.004847 * T) * sin(M) + (0.019993 - 0.000101 * T) * sin(2 * M) + 0.00029 * sin(3 * M));
f = M + C;
Obl = DEG_TO_RAD * (23 + 26 / 60.0 + 21.448 / 3600. - 46.815 / 3600 * T);
JDx = JDate - 2451545;
GrHrAngle = 280.46061837 + (360 * JDx) % 360 + 0.98564736629 * JDx + 360.98564736629 * JD_frac;
GrHrAngle = fmod(GrHrAngle, 360.0);
L_true = fmod(C + L0, 2 * PI);
R = 1.000001018 * (1 - e * e) / (1 + e * cos(f));
RA = atan2(sin(L_true) * cos(Obl), cos(L_true));
Decl = asin(sin(Obl) * sin(L_true));
HrAngle = DEG_TO_RAD * GrHrAngle + Lon - RA;
elevation = asin(sin(Lat) * sin(Decl) + cos(Lat) * (cos(Decl) * cos(HrAngle)));
azimuth = PI + atan2(sin(HrAngle), cos(HrAngle) * sin(Lat) - tan(Decl) * cos(Lat)); // Azimuth measured east from north, so 0 degrees is North
tt=(hour + minute / 60. + second / 3600.0);//time of a day in fractional hours
elecorr = -6.3568+3.1778*tt-0.65673*pow(tt,2)+0.062796*pow(tt,3)-0.0027617*pow(tt,4)+4.539e-5*pow(tt,5);//∆ele(calc-solartopo) elevation 04/04/20 from 6 to 20
azicorr = -49.389+18.258*tt-2.5262*pow(tt,2)+0.16238*pow(tt,3)-0.0048883*pow(tt,4)+5.5501e-5*pow(tt,5);//∆azi(calc-solartopo) azimuth for 04/04/20 from 6 to 20
//Serial.println(String(elecorr,3)+"\t"+String(azicorr,3));//for checking purposes
sun_azimuth = (azimuth / DEG_TO_RAD)-azicorr;
sun_elevation = (elevation / DEG_TO_RAD)-elecorr;
//Serial.println("Longitude and latitude " + String(Lon / DEG_TO_RAD, 5) + " " + String(Lat / DEG_TO_RAD, 5));//&&&To avoid printing headings on the monitor
//Serial.println("Year\tMonth\tDay\tHour\tMinute\tSecond\tElevation_corr.\tAzimuth_corr");//&&&To avoid printing headings on the monitor
Serial.print(String(year) + "\t" + String(month) + "\t" + String(day) + "\t" + String(hour - zone) + "\t" + String(minute) + "\t" + String(second) + "\t");
Serial.println(String(sun_elevation, 1) + "\t\t" + String(sun_azimuth, 1));
delay(2000);
}
double JulianDate(int year, int month, int day) {
double JDate;
int A, B;
if (month <= 2) {year--; month += 12;}
A = int(year / 100); B = 2 - A + int(A / 4);
JDate = (double)(365.25 * (year + 4716)) + (int)(30.6001 * (month + 1)) + day + B - 1524.5;
return JDate;
}
////////////// WiFi, Time and Date Functions /////////////////
int StartWiFi(const char* ssid, const char* password) {
int connAttempts = 0;
Serial.print(F("\r\nConnecting to: ")); Serial.println(String(ssid));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED ) {
delay(500); Serial.print(".");
if (connAttempts > 20) {
Serial.println("\nFailed to connect to a Wi-Fi network");
return false;
}
connAttempts++;
}
Serial.print(F("WiFi connected at: "));
Serial.println(WiFi.localIP());
delay(1000);// For ThingSpeak server
return true;
}
void StartTime() {
configTime(0, 0, "0.uk.pool.ntp.org", "time.nist.gov");
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1); // Roma
UpdateLocalTime();
}
void UpdateLocalTime() {
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
}
//See http://www.cplusplus.com/reference/ctime/strftime/
//Serial.println(&timeinfo, "%a %b %d %Y %H:%M:%S"); // Displays: Saturday, June 24 2017 14:05:49
char output[50];
//strftime(output, 50, "%a %d-%b-%y (%H:%M:%S)", &timeinfo);//&&&To avoid printing day, date and time on the monitor
time_str = output;
}
String GetTime() {
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time - trying again");
}
//See http://www.cplusplus.com/reference/ctime/strftime/
//Serial.println(&timeinfo, "%a %b %d %Y %H:%M:%S"); // Displays: Saturday, June 24 2017 14:05:49
char output[50];
strftime(output, 50, "%d/%m/%y %H:%M:%S", &timeinfo); //Use %m/%d/%y for USA format
time_str = output;
Serial.println(time_str);
return time_str; //returns date-time formatted like this "11/12/17 22:01:00"
}
String Update_DateTime() {
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time - trying again");
}
//See http://www.cplusplus.com/reference/ctime/strftime/
char output[50];
strftime(output, 50, "%H", &timeinfo);
current_hour = output;
strftime(output, 50, "%M", &timeinfo);
current_minute = output;
strftime(output, 50, "%d", &timeinfo);
current_day = output;
strftime(output, 50, "%m", &timeinfo);
current_month = output;
strftime(output, 50, "%Y", &timeinfo);
current_year = output;
Serial.println(time_str);
return time_str; // returns date-time formatted like this "11/12/17 22:01:00"
}
void test_azimuth() {
Azi_servo.write(90); // Centre position
delay(500);
Azi_servo.write(60); // Centre position
delay(500);
Azi_servo.write(120); // Centre position
delay(500);
Azi_servo.write(90); // Centre position
delay(500);
}
void test_elevation() {
for (int a = 5; a < 85; a = a + 2) {
Ele_servo.write(a); // Centre position
delay(30);
}
Ele_servo.write(85); // Centre position
delay(1000);
}
void reading_sensor () {
//Reading sensors
for(int i = 0; i < 1000; i++) {
LDRF += analogRead(36);
LDRR += analogRead(39);
delay(1);
}
//LDRF con filtro che attenua di ca. 40%_LDRR = 100% --> LDRF = 60%
LDRF /= 1000;LDRR /= 1000;
LDRF=LDRF*kf*100/LDRmax;LDRR=LDRR*kf*100/LDRmax;// % value of LDRs
//to test
Serial.println(String(LDRF)+"\t"+String(LDRR)+"\t");
pressure = bme.readPressure ()/100.0F;//pressione in hPa
humidity = bme.readHumidity();// umidità relativa
temperature = bme.readTemperature ();//temperatura in °C
altitude=(8.314*(temperature+273.15)/9.81)*log(pressure/SEALEVELPRESSURE_HPA); //1.29=densità aria kgm^-3; 9.81 acc.gravità ms^-2
altitude=49;//Su camino terrazzo altitude = 57 m
//p0(h")/p0(h') = exp(Q*∆h); Q = 9.81/((temperature+273.15)*287); at 298 K e ∆h = 1 m, p0(h")/p0(h') = 1.000115
p0 = pressure*exp(altitude*9.81/(287*(temperature+273.15)));//R* = 287 J kg-1 K-1 = constante dei gas per l’aria secca R* = R / Ma
// Add a 1 second delay.
delay(1000); //just here to slow down the output.
for(int i = 0; i < 1000; i++) {
shuntvoltageSP += ina219_SP.getShuntVoltage_mV();
busvoltageSP += ina219_SP.getBusVoltage_V();
currentSP_mA += ina219_SP.getCurrent_mA();
powerSP_mW += ina219_SP.getPower_mW();
loadvoltageSP = busvoltageSP + (shuntvoltageSP / 1000);
shuntvoltageBat += ina219_Bat.getShuntVoltage_mV();
busvoltageBat += ina219_Bat.getBusVoltage_V();
currentBat_mA += ina219_Bat.getCurrent_mA();
powerBat_mW += ina219_Bat.getPower_mW();
loadvoltageBat = busvoltageBat + (shuntvoltageBat / 1000);
shuntvoltageServo += ina219_Servo.getShuntVoltage_mV();
busvoltageServo += ina219_Servo.getBusVoltage_V();
currentServo_mA += ina219_Servo.getCurrent_mA();
powerServo_mW += ina219_Servo.getPower_mW();
loadvoltageServo = busvoltageServo + (shuntvoltageServo / 1000);
delay(1);
}
shuntvoltageSP/=1000;busvoltageSP/=1000;currentSP_mA/=1000;powerSP_mW/=1000;loadvoltageSP/=1000;
shuntvoltageBat/=1000;busvoltageBat/=1000;currentBat_mA/=1000;powerBat_mW/=1000;loadvoltageBat/=1000;
shuntvoltageServo/=1000;busvoltageServo/=1000;currentServo_mA/=1000;powerServo_mW/=1000;loadvoltageServo/=1000;
// Add a 1 second delay.
delay(1000); //just here to slow down the output.
//Reading GY-271
float x, y, z; float azi;
compass.read();
delay(500);
// Return XYZ readingsf
x = compass.getX();
y = compass.getY();
z = compass.getZ();
azi = compass.getAzimuth();
rho = sqrt(pow(x,2)+pow(y,2)+pow(z,2));
teta = acos(abs(z)/rho);
Zvalue = constrain(teta,PI*0.5/180,PI/2);// teta values between 0.5 - 90°
phi = acos(abs(x)/(rho*sin(Zvalue)));
teta = RAD_TO_DEG*teta; phi = RAD_TO_DEG*phi;
float bearing=((atan2(y,x))*180)/PI;//values will range from +180 to -180 degrees
float declinationAngle = (3.0 + (26.0 / 60.0));// Roma
bearing += declinationAngle;
if (bearing < 0) { bearing = 360 + bearing; }
float bearing2=((atan2(x,z))*180)/PI;//values will range from +180 to -180 degrees
if (bearing2 < 0) { bearing2 = 360 + bearing2; }
float bearing3=((atan2(z,y))*180)/PI;//values will range from +180 to -180 degrees
if (bearing3 < 0) { bearing3 = 360 + bearing3; }
// Calculate heading
// Set declination angle on your location and fix heading
// You can find your declination on: http://magnetic-declination.com/
// (+) Positive or (-) for negative
// For Bytom / Poland declination angle is 4'26E (positive)
// Formula: (deg + (min / 60.0)) / (180 / M_PI);
azi += declinationAngle*PI/180;// Value in radians
// Correct for heading < 0deg and heading > 360deg
if (azi < 0){
azi += 2 * PI;
}
if (azi > 2 * PI){
azi -= 2 * PI;
}
//Convert to degrees
float headingDegrees = azi * 180/M_PI;
//solo per test
Serial.print(String("X /µT") + "\t" + String("Y /µT") + "\t" + String("Z /µT") + "\t"+String("rho /µT")+"\t");
Serial.println();
Serial.print(String(x,1) + "\t" + String(y,1) + "\t" + String(z,1) + "\t"+String(rho,1)+"\t");
Serial.println();
Serial.println();
Serial.print(String("azimuth decl /°") + "\t" + String("teta /°") + "\t" + String("phi /°") + "\t");
Serial.println();
Serial.print(String(headingDegrees,1) + "\t" + String(teta,1) + "\t"+String(phi,1) + "\t");
Serial.println();
Serial.println();
Serial.print(String("bearing decl y,x /°") + "\t" + String("bearing x,z /°") + "\t" + String("bearing z,y /°") + "\t");
Serial.println();
Serial.print(String(bearing,1) + "\t" + String(bearing2,1) + "\t"+String(bearing3,1) + "\t");
Serial.println();
Serial.println();
//solo per test
Serial.println(String(pressure) +"/hPa" +"\t"+String(humidity)+"/%" +"\t"+String(temperature)+"/°C"+"\t"+String(p0) +"/hPa");
Serial.println("");
Serial.print("Bus Voltage SP: "); Serial.print(busvoltageSP); Serial.println(" V");
Serial.print("Shunt Voltage SP: "); Serial.print(shuntvoltageSP); Serial.println(" mV");
Serial.print("Load Voltage SP: "); Serial.print(loadvoltageSP); Serial.println(" V");
Serial.print("Current SP: "); Serial.print(currentSP_mA); Serial.println(" mA");
Serial.print("Power SP: "); Serial.print(powerSP_mW); Serial.println(" mW");
Serial.println("");
Serial.print("Bus Voltage Bat: "); Serial.print(busvoltageBat); Serial.println(" V");
Serial.print("Shunt Voltage Bat: "); Serial.print(shuntvoltageBat); Serial.println(" mV");
Serial.print("Load Voltage Bat: "); Serial.print(loadvoltageBat); Serial.println(" V");
Serial.print("Current Bat: "); Serial.print(currentBat_mA); Serial.println(" mA");
Serial.print("Power Bat: "); Serial.print(powerBat_mW); Serial.println(" mW");
Serial.println("");
Serial.print("Bus Voltage Servo: "); Serial.print(busvoltageServo); Serial.println(" V");
Serial.print("Shunt Voltage Servo: "); Serial.print(shuntvoltageServo); Serial.println(" mV");
Serial.print("Load Voltage Servo: "); Serial.print(loadvoltageServo); Serial.println(" V");
Serial.print("Current Servo: "); Serial.print(currentServo_mA); Serial.println(" mA");
Serial.print("Power Servo: "); Serial.print(powerServo_mW); Serial.println(" mW");
Serial.println("");
delay(1000);
// 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, password); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
//ThingSpeak Sun Tracker
{
ThingSpeak.setField(1, LDRF);//% Front photoresistor
ThingSpeak.setField(2, LDRR);//% Rear photoresistor
ThingSpeak.setField(3, loadvoltageServo);
ThingSpeak.setField(4, currentServo_mA);
ThingSpeak.setField(5, loadvoltageSP);
ThingSpeak.setField(6, currentSP_mA);
ThingSpeak.setField(7, loadvoltageBat);
ThingSpeak.setField(8, currentBat_mA);
// figure out the status0 message
if(temperature > 20){
myStatus0 = String("temperature is greater than 20 °C");
}
else if(pressure >= SEALEVELPRESSURE_HPA){
myStatus0 = String("altitude equal to BME280 altitude");
}
else if(humidity >= 50.0){
myStatus0 = String("relative humidity ≥ 50%");
}
else{
myStatus0 = String("");
}
// set the status
ThingSpeak.setStatus(myStatus0);
// write to the ThingSpeak channel myChNo0
int x = ThingSpeak.writeFields(myChNo0, myWriteAPIKey0);
if(x == 200){
Serial.println("Channel_myChNo#0_ update successful.");
}
else{
Serial.println("Problem updating channel_myChNo#0. HTTP error code " + String(x));
}
delay(10000); //Ritardo di 10 s per consentire acq
}
//Meteo
{
ThingSpeak.setField(1, sun_azimuth);
ThingSpeak.setField(2, sun_elevation);
ThingSpeak.setField(3, x);
ThingSpeak.setField(4, y);
ThingSpeak.setField(5, z);
ThingSpeak.setField(6, azi);
ThingSpeak.setField(7, p0);
ThingSpeak.setField(8, temperature);
// figure out the status1 message
if(temperature > 20){
myStatus1 = String("temperature is greater than 20 °C");
}
else if(pressure >= SEALEVELPRESSURE_HPA){
myStatus1 = String("altitude equal to BME280 altitude");
}
else if(humidity >= 50.0){
myStatus1 = String("relative humidity ≥ 50%");
}
else{
myStatus1 = String("");
}
// set the status
ThingSpeak.setStatus(myStatus1);
// write to the ThingSpeak channel myChNo#1
int x1 = ThingSpeak.writeFields(myChNo1, myWriteAPIKey1);
if(x1 == 200){
Serial.println("Channel_myChNo1_ update successful.");
}
else{
Serial.println("Problem updating channel_myChNo1. HTTP error code " + String(x1));
}
delay(10000); //Ritardo di 10 s per consentire acq
}
/*
//Checking servo current_restart for resetting the right position of servos
if(currentServo_mA > 300.) {
delay(10000);
ESP.restart();
}
*/
//Checking servo current_restart for resetting the right position of servos
if(currentServo_mA > 300.) {
test_azimuth();
delay(1000);
test_elevation(); // Stop at 85 which is vertical or 0 elevation
delay(1000);
}
}
/ /Thank you
Daniele Gozzi
Daniele Gozzi on 4 May 2020
Sorry, but I cannot find your comment.
Did you change some lines in the code? If so tell me, please, where.
Thank you

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!