praegune kellaaeg 18.06.2025 15:35:37
|
Hinnavaatlus
:: Foorum
:: Uudised
:: Ärifoorumid
:: HV F1 ennustusvõistlus
:: Pangalink
:: Telekavad
:: HV toote otsing
|
|
autor |
|
Terror
HV veteran

liitunud: 08.11.2001
|
29.01.2015 12:06:24
Arduino HTTP GET |
|
|
Kuluks väike abi ära mikrokontrolleri abil veebilehelt väärtuse lugemisega.
https://github.com/nmattisson/HttpClient <- selline library on kasutada.
Aadress kust väärtust on vaja lugeda on: https://thingspeak.com/channels/24877/fields/1/last.json
Vaja oleks sealt saada boldiga väärtused (st sobiks, kui saaks terve selle rea alustuseks ning hijlem vaataks kuidas filtreerida) : ("created_at":"2015-01-29T06:32:06Z","entry_id":15,"field1":"17.9")}
Kuna pole netist andmete tõmbamisega eelnevalt kokku puutunud, siis ei oska suurt midagi peale hakata. All library näidis kus muutsin veebilehe aadressi õigeks, mida seal veel muuta oleks vaja?
http_header_t headers[] = {
// { "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "thingspeak.com";
request.port = 80;
request.path = "/channels/24877/fields/1?results=1";
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
}
|
|
|
Kommentaarid: 100 loe/lisa |
Kasutajad arvavad: |
   |
:: |
1 :: |
2 :: |
91 |
|
tagasi üles |
|
 |
riaak
HV Guru

liitunud: 22.09.2002
|
|
Kommentaarid: 119 loe/lisa |
Kasutajad arvavad: |
   |
:: |
0 :: |
1 :: |
105 |
|
tagasi üles |
|
 |
Terror
HV veteran

liitunud: 08.11.2001
|
30.01.2015 19:42:54
|
|
|
Sain asja funksima.
Hetke kood selline (tahaks puhastamist saada):
Spoiler 
// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"
// This #include statement was automatically added by the Spark IDE.
#include "TimeAlarms/TimeAlarms.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_mfGFX/Adafruit_mfGFX.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_ILI9341/Adafruit_ILI9341.h"
char displayText[64];
Adafruit_ILI9341 tft = Adafruit_ILI9341(A2, A1, A0);
float minTemp = 100;
float maxTemp = -100;
float hetkeTemp = 0;
int update = 0;
int i=0;
String timeStr;
String timeMax;
String timeMin;
unsigned long check = 0;
unsigned int uptime = 0;
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "Content-Type", "application/json" },
// { "Accept" , "application/json" },
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Time.zone(+2);
Alarm.alarmRepeat(01,00,00, MidnightAlarm);
Alarm.timerRepeat(20, Repeats);
Serial.begin(9600);
tft.begin();
tft.fillScreen(ILI9341_WHITE);
}
void loop() {
//digitalClockDisplay();
Serial.println();
Alarm.delay(100);
}
void Repeats(){
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "api.thingspeak.com";
request.port = 80;
request.path = "/channels/24877/fields/1/last.json?key";
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
if(response.status == 200){
Serial.print("Application>\tHTTP Response Body: ");
String web = response.body;
String aeg2 = web.substring(28,34);
String aeg1 = web.substring(26,28);
int gmt = atof(aeg1.c_str());
int tund = gmt + 2;
timeStr = "";
timeStr += tund;
timeStr += aeg2;
timeStr += "";
int last = web.lastIndexOf('"');
int previous = web.lastIndexOf('"', last - 1 );
String result = web.substring(previous+1, last);
hetkeTemp = atof(result.c_str());
Serial.println(timeStr);
uptime=millis()/1000/60/60;
if(hetkeTemp>-40 && hetkeTemp <50){
if (minTemp>hetkeTemp){
minTemp=hetkeTemp;
timeMin = "";
if(Time.hour()<10){timeMin +=" ";}
timeMin += Time.hour();
timeMin += ":";
if(Time.minute()<10){timeMin +="0";}
timeMin += Time.minute();
}
if (maxTemp<hetkeTemp){
maxTemp=hetkeTemp;
timeMax = "";
if(Time.hour()<10){timeMax +=" ";}
timeMax += Time.hour();
timeMax += ":";
if(Time.minute()<10){timeMax +="0";}
timeMax += Time.minute();
}
tft.setRotation(1);
tft.setTextColor(ILI9341_BLACK, ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(160,3);
tft.print(uptime);
tft.setTextSize(8);
tft.setCursor(40,30);
if(hetkeTemp>0){tft.print("+");}
tft.print(hetkeTemp,1);
tft.setTextSize(3);
tft.setCursor(40,120);
tft.print("MAX ");
tft.setTextSize(2);
tft.setCursor(40,145);
tft.print(timeMax);
tft.setCursor(150,120);
tft.setTextSize(5);
if(maxTemp>0){tft.print("+");}
tft.print(maxTemp,1);
tft.setTextSize(3);
tft.setCursor(40,170);
tft.print("MIN ");
tft.setTextSize(2);
tft.setCursor(40,195);
tft.print(timeMin);
tft.setCursor(150,170);
tft.setTextSize(5);
if(minTemp>0){tft.print("+");}
tft.print(minTemp,1);
tft.setTextSize(2);
tft.setCursor(110,222);
tft.print(timeStr);
}
}
}
void MidnightAlarm(){
minTemp = hetkeTemp;
maxTemp = hetkeTemp;
Spark.syncTime();
}
|
Temp andur ise selline:
Kasutasin ära seinal olevat suuremat elektri harukarpi. Näitab hetke tempi, jooksva päeva max/min tempi koos nende kellaaegadega ning all olev aeg näitab millal tempi uuendati. Üleval olev 0 on uptime tundides - testimise eesmärgil hetkel.
|
|
Kommentaarid: 100 loe/lisa |
Kasutajad arvavad: |
   |
:: |
1 :: |
2 :: |
91 |
|
tagasi üles |
|
 |
|
lisa lemmikuks |
|
|
sa ei või postitada uusi teemasid siia foorumisse sa ei või vastata selle foorumi teemadele sa ei või muuta oma postitusi selles foorumis sa ei või kustutada oma postitusi selles foorumis sa ei või vastata küsitlustele selles foorumis sa ei saa lisada manuseid selles foorumis sa võid manuseid alla laadida selles foorumis
|
|
Hinnavaatlus ei vastuta foorumis tehtud postituste eest.
|