Good afternoon everybody.
I have a problem with httpGETrequest.
Last year I started to do the project on Arduino. It is clock, that shows general information about kite spots.
Last year the site where I was taken data had http, and I didn’t had any problem with this protocol.
This year site is updated and now it has https.
I founded an instruction how to make this connection insecure.
I did everything, and everything worked, but with one problem. When I do Serial.print(http.getString()), I can see get request in serial monitor.
When I do this thing String payload = http.getString()
Serial.print(payload), payload is empty.
I’m working with blynk library also.
This is my code:
https://drive.google.com/drive/folders/1X1-geNEz1_JWZrt_xdp_dCvGaWxBVwWy?usp=sharing
Here you can see/download the full code.
I can’t attach directly any file, because i’m a new user.
Thank you!
This is only part of my code. But here I have a problem.
I wrote PROBLEM on problematic line!
/**
BasicHTTPClient.ino
Created on: 24.05.2015
*/
// include the SevenSegmentTM1637 library
#define USE_SERIAL Serial
#define BLYNK_PRINT Serial
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266HTTPClient.h>
#include <Arduino.h>
//#include <WiFi.h>
//#include <BlynkSimpleEsp32.h>
//#include <HTTPClient.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
WiFiClientSecure client;
HTTPClient https;
HTTPClient http1;
HTTPClient http2;
HTTPClient http3;
WidgetRTC rtc;
// Set password to "" for open networks.
const char ssid[] = "TIM-32340613";
const char pass[] = "CGyNGmxwDq1vvtQ9ZbIiYwzP";
//const char ssid[] = "AndroidAP";
//const char pass[] = "66990000";
char auth[] = "nBoQTuLO5ToES5aVb4AAgQL8MmWn9gCE";
// the IP address for the shield:
IPAddress local_IP(192, 168, 1, 204);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
//IPAddress server ("bblink.sytes.net");
float campione_wind_speed;
String campione_wind_direction;
float campione_temperature;
int campione_wind_speed_old;
int A = 0;
float garda_wind_speed;
String garda_wind_direction;
float garda_temperature;
float garda_humidity;
int garda_pressure;
int garda_wind_speed_old;
int B = 0;
unsigned long timer = 0, timer_blynk = 0;
int G = 0;
bool Camp = 1, Made = 0, Tim = 0;
bool cwind, ctemp, cdir, mwind, mtemp, mdir, temp;
byte M;
bool Propusk = 0;
byte svet = 0;
const byte PIN_CLK = 2; // define CLK pin (any digital pin)
const byte PIN_DIO = 0; // define DIO pin (any digital pin)
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
BLYNK_WRITE(V8)
{
cwind = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V9)
{
ctemp = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V10)
{
cdir = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V12)
{
mwind = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V13)
{
mtemp = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V14)
{
mdir = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V15)
{
temp = param.asInt(); // Get value as integer
}
BLYNK_WRITE(V18)
{
svet = param.asInt();
display.setBacklight(svet);
}
BLYNK_APP_CONNECTED() {
Blynk.syncAll();
}
BLYNK_CONNECTED() {
Blynk.syncAll();
rtc.begin();
}
void setup() {
display.begin(); // initializes the display
display.setBacklight(100); // set the brightness to 100 %
Serial.begin(115200);
Blynk.config(auth, "bblink.sytes.net", 8080);
// if (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) {
// display.print("err");
// Serial.print("error");
//}
WiFi.begin(ssid, pass);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(2000);
}
Serial.println("\nConnected to the WiFi network");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.gatewayIP());
display.print("CONNECTED");
delay(1000);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
Blynk.run();
}
if (cwind == 1 || ctemp == 1 || cdir == 1 || mwind == 1 || mtemp == 1 || mdir == 1 || temp == 1) {
display.setBacklight(svet);
if (Camp == 1) {
Campione();
}
if (Made == 1) {
Maderno();
}
if (Tim == 1) {
Time();
}
}
else {
display.setBacklight(0); // set the brightness to 100 %
}
blynk();
}
void Campione() {
if (cwind == 1 || ctemp == 1 || cdir == 1 ) {
// wait for WiFi connection
if ((WiFi.status() == WL_CONNECTED)) {
if (millis() - timer > 5000 ) {
client.setInsecure(); //the magic line, use with caution
//client.connect("https://www.kitecampione.com/mobile/", 433);
USE_SERIAL.print("[HTTP] begin...\n");
https.begin(client, "https://www.kitecampione.com/mobile/"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString(); !!!!!!!!!!!!!!!!PROBLEM!!!!!!!!!!!!!!!!
USE_SERIAL.println(payload); !!!!!!!!!!!!!!!!PROBLEM!!!!!!!!!!!!!!!!
if (mwind == 1 || mtemp == 1 || mdir == 1 || temp == 1) {
if (G == 0) {
display.setColonOn(false);
display.clear();
display.print("CAMPIONE");
Propusk = 1;
}
}
else {
M++;
}
Serial.println("pppp");
char a[] = {payload[6477], payload[6478], payload[6479], payload[6480]};
String d = "";
int f = 4;
int r = 1;
int i;
bool but = 0;
if (ctemp == 1) {
if (G == (1 - M)) {
for ( i = 6706; i < 6721; i++) {
if ((int)payload[i] > 47 && (int)payload[i] < 58) {
d += payload[i];
r *= 10;
}
if ((int)payload[i] == 46) {
but = 1;
}
if (i == 6720) {
display.clear();
display.setColonOn(true);
if (r == 10) {
display.setCursor(0, 1);
display.print(d + "0C");
}
if (r == 100) {
if (but == 1) {
display.setCursor(0, 1);
display.print(d + "C");
}
else {
display.print(d + "0C");
}
}
if (r == 1000) {
display.print(d + "C");
}
}
}
Propusk = 1;
}
}
else {
M ++;
}
if (cwind == 1) {
if (G == (2 - M)) {
for ( i = 0; i < 4; i++) {
if ((int)a[i] > 47 && (int)a[i] < 58) {
d += a[i];
r *= 10;
}
if (i == 3) {
display.clear();
display.setColonOn(true);
if (r == 10) {
display.setCursor(0, 1);
display.print(d + "0K");
}
if (r == 100) {
if ((int)a[1] == 46) {
display.setCursor(0, 1);
display.print(d + "K");
}
else {
display.print(d + "0K");
}
}
if (r == 1000) {
display.print(d + "K");
}
}
}
Propusk = 1;
}
}
else {
M++;
}
if (cdir == 1) {
if (G == (3 - M)) {
for ( i = 6597; i < 6608; i++) {
if ((int)payload[i] > 64 && (int)payload[i] < 91) {
d = d + payload[i];
f--;
}
if (i == 6607) {
display.setColonOn(false);
display.clear();
display.setCursor(0, f);
display.print(d);
campione_wind_direction = d;
}
}
Propusk = 1;
}
}
else {
M++;
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
display.clear(); // clear the display
display.print("err "); // display LOOP on the display
Propusk = 1;
G = 3;
delay(1000);
}
https.end();
}
if (Propusk == 1) {
timer = millis();
G ++;
Propusk = 0;
}
}
}
else {
display.print("no internet ");
G = 4;
}
}
else {
G = 4;
}
if (G == (4 - M)) {
G = 0;
Camp = 0;
Made = 1;
Tim = 0;
}
M = 0;
}