There are lots of string functions in Arduino but my problem is that I don´t know which of them I should use. And - since I never did this before I honestly don´t know how this is to be done!!
I would really appreciate your help - heres the sketch of my nodemcu:
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define Serial Serial
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#include "SPI.h"
ESP8266WiFiMulti WiFiMulti;
//Pinout of display
#define TFT_CS D0 // GPIO 16
#define TFT_RST 10 // D12 GPIO10
#define TFT_DC D1 // GPIO 5
#define TFT_MOSI D7 // GPIO 13
#define TFT_CLK D5 // GPIO 14
#define TFT_MISO D6 // GPIO 12
Adafruit_ILI9340 tft = Adafruit_ILI9340(TFT_CS, TFT_DC, TFT_RST);
#define ROTATION_NO 0
#define ROTATION_90 1
#define ROTATION_180 2
#define ROTATION_270 3
String weatherdata;
void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("", "");
tft.begin();
tft.setRotation( ROTATION_270);
tft_printframe();
tft_printcaption();
}
//Void setup() end
void tft_printcaption(void)
{
tft.setTextColor(ILI9340_WHITE);
//tft.setCursor( 10,55);
//tft.setTextSize(2);
//tft.print("");
tft.setTextSize(1);
//tft.print("O");
tft.setTextSize(3);
//tft.print("C");
tft.setTextSize(2);
tft.setCursor( 50, 15);
tft.print(" HPascal");
tft.setTextSize(2);
tft.setCursor( 10, 210);
tft.print(" Percent");
}
void tft_printframe( )
{
tft.fillScreen(ILI9340_BLACK);
tft.drawRoundRect(1, 0, tft.width() - 1, 40, 10, ILI9340_BLUE);
tft.drawRoundRect(1, 50, tft.width() - 1, 135, 10, ILI9340_GREEN);
tft.drawRoundRect(0, 200, tft.width() - 1, 40, 10, ILI9340_RED);
}
void tft_show_weatherdata()
{
tft.setTextSize(4);
tft.setTextColor(ILI9340_YELLOW, ILI9340_BLACK );
tft.setCursor(0, 50);
tft.print(weatherdata);
}
void loop(void) {
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("http://192.168.1.15/?mode=text");
Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
Serial.println();
// file found at server
if (httpCode == HTTP_CODE_OK) {
weatherdata = http.getString(); // That´s the variable that i want to split!!
Serial.println(weatherdata);
tft_show_weatherdata();
}
}
else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
}