Error while using thing HTTP
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NAGUBATHULA SATYA SRIRAM
el 24 de Mayo de 2022
Editada: Christopher Stapels
el 26 de Mayo de 2022
While i have written a code and transmitted the values to thing speak and now iam trying to use message alerts with twilio and included HTTP and while using it iam getting an error.
the code is as follows and iam highlighting the error and the error [ is exit status 1
'HTTPClient' was not declared in this scope]
/*
WriteMultipleFields
Description: Writes values to fields 1,2,3,4 and status in a single ThingSpeak update every 20 seconds.
Hardware: Arduino Uno WiFi Rev2
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
Note:
- Requires WiFiNINA library.
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel.
Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed.
See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation.
For licensing information, see the accompanying license file.
Copyright 2020, The MathWorks, Inc.
*/
#include <WiFiNINA.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
#include <ArduinoHttpClient.h>
// the libraries of the ph sensor and varibles defined
#include <Wire.h>
float calibration_value = 21.34-5.5;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10],temp;
// the libraries of tds sensor and varibles are declared here
#include <EEPROM.h>
#include "GravityTDS.h"
#define TdsSensorPin A1
GravityTDS gravityTds;
float temperature = 25,tdsValue = 0;
//the libraries of dissolved oxygen meter are declared here
#include <Arduino.h>
#define DO_PIN A2
#define VREF 5000 //VREF (mv)
#define ADC_RES 1024 //ADC Resolution
//Single-point calibration Mode=0
//Two-point calibration Mode=1
#define TWO_POINT_CALIBRATION 0
#define READ_TEMP (25) //Current water temperature ℃, Or temperature sensor function
//Single point calibration needs to be filled CAL1_V and CAL1_T
#define CAL1_V (1831) //mv
#define CAL1_T (25) //℃
//Two-point calibration needs to be filled CAL2_V and CAL2_T
//CAL1 High temperature point, CAL2 Low temperature point
#define CAL2_V (1300) //mv
#define CAL2_T (15) //℃
const uint16_t DO_Table[41] = {
14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530,
11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270,
9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690,
7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410};
uint8_t Temperaturet;
uint16_t ADC_Raw;
uint16_t ADC_Voltage;
uint16_t DO;
uint16_t dissolved;
int16_t readDO(uint32_t voltage_mv, uint8_t temperature_c)
{
#if TWO_POINT_CALIBRATION == 0
uint16_t V_saturation = (uint32_t)CAL1_V + (uint32_t)35 * temperature_c - (uint32_t)CAL1_T * 35;
return (voltage_mv * DO_Table[temperature_c] / V_saturation);
#else
uint16_t V_saturation = (int16_t)((int8_t)temperature_c - CAL2_T) * ((uint16_t)CAL1_V - CAL2_V) / ((uint8_t)CAL1_T - CAL2_T) + CAL2_V;
return (voltage_mv * DO_Table[temperature_c] / V_saturation);
#endif
}
//wifi and api keys are declared here
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
WiFiClient client;
boolean checkpoint= true;
boolean checkpoint1= true;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
// Initialize our values
int number1 = 0;
int number2 = random(0,100);
int number3 = random(0,100);
int number4 = random(0,100);
String myStatus = "";
void setup() {
Serial.begin(9600); // Initialize serial
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin(); //initialization
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv != "1.0.0") {
Serial.println("Please upgrade the firmware");
}
ThingSpeak.begin(client); //Initialize ThingSpeak
}
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.");
}
// TDS sensor values starts from here
gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print(tdsValue,0);
Serial.println("ppm");
delay(1000);
// ph meter values and code here
for(int i=0;i<10;i++)
{
buffer_arr[i]=analogRead(A0);
delay(30);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buffer_arr[i]>buffer_arr[j])
{
temp=buffer_arr[i];
buffer_arr[i]=buffer_arr[j];
buffer_arr[j]=temp;
}
}
}
avgval=0;
for(int i=2;i<8;i++)
avgval+=buffer_arr[i];
float volt=(float)avgval*5.0/1024/6;
float ph_act = -5.70 * volt + calibration_value;
Serial.println(ph_act);
delay(1000);
// dissolved oxygen meter starts from here
Temperaturet = (uint8_t)READ_TEMP;
ADC_Raw = analogRead(DO_PIN);
ADC_Voltage = uint32_t(VREF) * ADC_Raw / ADC_RES;
Serial.print("Temperaturet:\t" + String(Temperaturet) + "\t");
Serial.print("ADC RAW:\t" + String(ADC_Raw) + "\t");
Serial.print("ADC Voltage:\t" + String(ADC_Voltage) + "\t");
Serial.println("DO:\t" + String(readDO(ADC_Voltage, Temperaturet)) + "\t");
delay(1000);
if (ph_act < 4)
{
if(checkpoint)
{
HTTPClient http; [errror]
Serial.println("[HTTP] begin...\n");
String str= String(h)+"pH has reached ";
http.begin("https://api.thingspeak.com/apps/thinghttp/send_request?api_key=GCA8S03FIUORHJJM0&message="+str);
Serial.print("[HTTP] begin...\n");
int httpcode= http.GET();
if(httpcode >0)
{
Serial.printf("[HTTP] GET...code :%d\n",httpcode);
if(httpcode=HTTP_CODE_OK)
{
String payload=http.GETString();
Serial.println(payload);
checkpoint= false;
}
}
}
}
else {
checkpoint=true;
}
}
// set the fields with the values
ThingSpeak.setField(1, ph_act);
ThingSpeak.setField(2, tdsValue);
ThingSpeak.setField(3, float(ADC_Voltage));
ThingSpeak.setField(4, Temperaturet);
// figure out the status message
if(number1 > number2){
myStatus = String("field1 is greater than field2");
}
else if(number1 < number2){
myStatus = String("field1 is less than field2");
}
else{
myStatus = String("field1 equals field2");
}
// set the status
ThingSpeak.setStatus(myStatus);
// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}
// change the values
number1++;
if(number1 > 99){
number1 = 0;
}
number2 = random(0,100);
number3 = random(0,100);
number4 = random(0,100);
delay(15000); // Wait 20 seconds to update the channel again
}
6 comentarios
Christopher Stapels
el 25 de Mayo de 2022
Using the code patterns I suggested above, Ive definitely succeeded in creating working code that accesses ThingSpeak channels and ThingHTTP in the same code. I suggest you simplify and try to do one task at a time. Then you can make functions in your code that do those tasks.
NAGUBATHULA SATYA SRIRAM
el 26 de Mayo de 2022
Editada: Christopher Stapels
el 26 de Mayo de 2022
Respuestas (0)
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Ver también
Categorías
Más información sobre Write Data to Channel en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!