arduino mega 2560 how to download Thingspeak information

This is my program.It is not read JSON.
how to revise?
Please help me!!
It is very emergency. :frowning:

#include <Wire.h>
#include <ArduinoJson.h>
#include "DHT.h" //DHT空氣感測器標頭碼
#include <SoftwareSerial.h> //串列物標頭碼
#include <LiquidCrystal_I2C.h> //LCD_I2C標頭碼
LiquidCrystal_I2C LCD(0x27,16,2);// LCD名稱
DHT myDHT(A0,DHT11); //定義DHT腳位A0與名稱
int C; //定義C,H,W變數
int H;
int W;
#define wet A1 //土壤感測器腳位
#define RY1 2 // 啟動繼電器腳位
#define t0 "Celsius:"
#define t1 "Humidity:"
#define t2 "wet_level:"
#define SSID "wifi3538" //WiFi帳號
#define PASS "redacted" //WiFi密碼
#define IP "184.106.153.149" //雲端網誌IP
String GET = "GET /update?key=G9YO13C2ZOXC94DA"; //雲端表格ID
String GET2 = "GET /channels/328362/fields/1.json?key=redacted";
void setup() {
pinMode(wet,INPUT); //定義wet為輸入腳
pinMode(RY1,OUTPUT); //定義RY1為輸出腳
LCD.begin(); // LCD初始化
LCD.backlight(); //LCD背光開啟
LCD.home(); //LCD歸位
LCD.print(t0); //在LCD顯示t0文字
Serial.begin(9600);//啟動串列物視窗 包率為9600
myDHT.begin(); //空氣感測器啟動
Serial1.begin(115200); //WiFi晶片包率為9600
Serial.println("AT"); //在串列物視窗輸入AT
Serial1.println("AT"); //在WiFi視窗輸入AT
delay(3000); //延遲3秒
if(Serial1.find("OK"))
{
Serial.println("RECEIVED: OK\nData ready to sent!");
connectWiFi();
}
else{
Serial.println("NO RESEPONCE!");
}
}
void loop() {
retrieveField(328362,1);
for(int i=0;i<5;i++) //設i為變數,並執行5次
{
C=myDHT.readTemperature(0);//讀取攝氏溫度,放入C變數
H=myDHT.readHumidity(); //讀取空氣濕度,放入H變數
W=analogRead(wet); //讀取土壤濕度,放入W變數
Serial.println(t2); //測試.....在串列物顯示t2文字與W變數數值
Serial.println(W);
if(W>150) //如果W>150則RY1寫入高態,否則寫入低態
{
digitalWrite(RY1,1);

delay(100);
}
else{
digitalWrite(RY1,0);
delay(100);
}
LCD.begin(); //LCD初始化
LCD.print(t0); //在LCD顯示t0文字
LCD.print(C); //在LCD顯示攝氏溫度數值
LCD.setCursor(0,1); //下一列
LCD.print(t1); //在LCD顯示t1文字
LCD.print(H); //在LCD顯示空氣濕度數值
delay(2000); //延遲2秒
LCD.setCursor(0,1); //下一列
LCD.print(t2); //在LCD顯示t2文字
LCD.print(W); //在LCD顯示土壤溼度數值
delay(2000); //延遲2秒
}
W=analogRead(wet); //讀取W變數數值
delay(100); //延遲0.1秒
Serial.println(t2); //在串列物視窗顯示t2文字與W變數數值
Serial.println(W);
SentOnCloud( String (C), String (H), String (W)); //傳送 C,H,W數值到雲端網站
}

boolean connectWiFi()
{
String cmd="AT+CWJAP="";
cmd+=SSID;
cmd+="","";
cmd+=PASS;
cmd+=""";
Serial1.println(cmd);
delay(3000);
while(1){
if(Serial1.find("OK"))
{
Serial.println("Connect AP: OK");
break;
}
else
{
Serial.println("Connect AP: Error");
}
}
}
void SentOnCloud( String C, String H, String W )
{
// 設定 ESP8266 作為 Client 端
String cmd = "AT+CIPSTART="TCP","";
cmd += IP;
cmd += "",80";
Serial.println(cmd);
Serial1.println(cmd);
delay(1000);
if( Serial1.find( "Error" ) )
{
Serial.print( "CIPSTART: Error\nExit1" );
return;
}
cmd = GET + "&field1=" + C + "&field2=" + H +"&field3=" + W +"\r\n";//資料放上THINK網站
Serial.println( cmd.length());
Serial1.print( "AT+CIPSEND=" );
Serial1.println( cmd.length() );
if(Serial1.find( ">" ) )
{
Serial.print(">");
Serial.print(cmd);
Serial1.print(cmd);
}
else
{
Serial1.print( "AT+CIPCLOSE" );
}
if( Serial1.find("OK") )
{
Serial.println( "Data send: OK" );
}
else
{
Serial.println( "Data send: Error\nExit2" );
}
}
void retrieveField( uint32_t channel2_id, uint8_t field2_id )
{
String cmd = "AT+CIPSTART="TCP","";
cmd += IP;
cmd += "",80";
Serial.println(cmd);
Serial1.println(cmd);
delay(1000);
if( Serial1.find( "Error" ) )
{
Serial.print( "CIPSTART: Error\nExit1" );
return;
}
cmd = GET2 + "&results=" + 1 +"\r\n";
Serial.println( cmd.length());
Serial1.print( "AT+CIPSEND=" );
Serial1.println( cmd.length() );
if(Serial1.find( ">" ) )
{
Serial.print(">");
Serial.print(cmd);
Serial1.print(cmd);
}
else
{
Serial.println( "AT+CIPCLOSE" );
Serial1.print( "AT+CIPCLOSE" );
}
String section="HEAD";
// 讀取所有從 ThingSpeak IoT Server 的回應並輸出到串列埠
while(Serial1.available())
{
String line = Serial1.readStringUntil('\r');
Serial.print(line);
}
}

The program you incorrectly posted does something. Seems that you forgot to tell us what it actually does.

You expect the program, that you failed to post properly, to do something. Seems that you forgot to tell us what you expect it to do.

Seems that you forgot to post your serial output, too.

Sorry, did not tell you the purpose of this procedure.

The purpose of this program is to do air temperature upload and return,but there will be some problems in return.

In the program "retrieveField" is a subroutine to return data.

In Serial1, enter "GET /channels/328362/fields/1.json?key= UFEOHVGWKE0K32KR + & results =" + 1 + "\ r \ n" The tandem window does not display the site's JSON text.

I hope you guys give me some suggestions, thanks. :smiley:

What is connected to the Serial1 pins?

Why are you including SoftwareSerial.h?

What DO you see in the Serial Monitor app dialog?

"SoftwareSerial.h" is related to the board I use.

arduino mega 2560 has 3 external tandem pins.

I use the first serial pin, so I have to name Serial1.

Serail1 has RX and TX pins, in order to connect ESP8266.

This blog will give you a better understanding of the board to which I apply https://www.arduino.cc/en/Main/ArduinoBoardMega

"SoftwareSerial.h" is related to the board I use.

The Mega has 4 hardware serial ports. Why do you need to use SoftwareSerial?

Actually, the question was why do you include this header file when you don't actually use the class? You don't create an instance of the class, so there is no reason to include the class definition.

arduino mega 2560 has 3 external tandem pins.

What?

This blog will give you a better understanding of the board to which I apply

That isn't a blog, and I KNOW what a Mega is, and what it can do. YOU are the one that needs to pay more attention to that page.