Beskrivning Ett test att genom enkel kod kunna hämta nästa avgång för en specifik plats och presentera detta på en enklare display. Tänkt för hemmabruk/privat. Kommentarer ESP8266 + LCD 20x4 New #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); const char* ssid = "--name--"; const char* password = "--pw--"; const char* host = "--url--"; const int httpPort = 80; String line; String url = "--file--"; boolean valid = false; void setup() { lcd.begin(20, 4); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } lcd.print("Wifi connected!"); lcd.setCursor(0, 1); lcd.print(WiFi.localIP()); } void loop() { lcd.clear(); WiFiClient client; lcd.setCursor(0, 0); if (!client.connect(host, httpPort)) { lcd.print("fail"); valid = false; } else { lcd.print("OK"); valid = true; } if (valid) { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); delay(1000); while (client.available()) { line = client.readStringUntil('|'); } int s1 = (line.indexOf('<') + 1); int e1 = line.indexOf('>'); if (line.substring(s1, e1)) { int s2 = (line.indexOf('<', (e1 + 1)) + 1); int e2 = line.indexOf('>', (e1 + 1)); int s3 = (line.indexOf('<', (e2 + 1)) + 1); int e3 = line.indexOf('>', (e2 + 1)); int s4 = (line.indexOf('<', (e3 + 1)) + 1); int e4 = line.indexOf('>', (e3 + 1)); int s5 = (line.indexOf('<', (e4 + 1)) + 1); int e5 = line.indexOf('>', (e4 + 1)); int s6 = (line.indexOf('<', (e5 + 1)) + 1); int e6 = line.indexOf('>', (e5 + 1)); int s7 = (line.indexOf('<', (e6 + 1)) + 1); int e7 = line.indexOf('>', (e6 + 1)); lcd.setCursor(0, 0); lcd.print(line.substring(s1, e1)); //TID lcd.setCursor(0, 1); lcd.print(line.substring(s2, e2)); //Dest lcd.setCursor(14, 1); lcd.print(line.substring(s3, e3)); //Tid lcd.setCursor(0, 2); lcd.print(line.substring(s4, e4)); //Dest lcd.setCursor(14, 2); lcd.print(line.substring(s5, e5)); //Tid lcd.setCursor(0, 3); lcd.print(line.substring(s6, e6)); //Dest lcd.setCursor(14, 3); lcd.print(line.substring(s7, e7)); //Tid ESP.deepSleep(30e6); } } } Logga in eller registrera dig för att kunna kommentera --file-- New <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $url = "http://api.sl.se/api2/realtimedeparturesV4.xml?key=--API_NYCKEL--&siteid=--STATION--&timewindow=60"; $xml = simplexml_load_file($url); //print_r($xml); $json = json_encode($xml); $array = json_decode($json,TRUE); echo("< "); echo(substr($array["ResponseData"]["LatestUpdate"],11,16)); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["0"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["0"]["DisplayTime"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["1"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["1"]["DisplayTime"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["2"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["2"]["DisplayTime"]." "); print_r(">|"); ?> Logga in eller registrera dig för att kunna kommentera (Inget ämne) New Logga in eller registrera dig för att kunna kommentera Detaljer Projektstatus Test Taggar ESP8266 #arduino #Realtid Deltagare tidsoptimisten
ESP8266 + LCD 20x4 New #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4); const char* ssid = "--name--"; const char* password = "--pw--"; const char* host = "--url--"; const int httpPort = 80; String line; String url = "--file--"; boolean valid = false; void setup() { lcd.begin(20, 4); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } lcd.print("Wifi connected!"); lcd.setCursor(0, 1); lcd.print(WiFi.localIP()); } void loop() { lcd.clear(); WiFiClient client; lcd.setCursor(0, 0); if (!client.connect(host, httpPort)) { lcd.print("fail"); valid = false; } else { lcd.print("OK"); valid = true; } if (valid) { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); delay(1000); while (client.available()) { line = client.readStringUntil('|'); } int s1 = (line.indexOf('<') + 1); int e1 = line.indexOf('>'); if (line.substring(s1, e1)) { int s2 = (line.indexOf('<', (e1 + 1)) + 1); int e2 = line.indexOf('>', (e1 + 1)); int s3 = (line.indexOf('<', (e2 + 1)) + 1); int e3 = line.indexOf('>', (e2 + 1)); int s4 = (line.indexOf('<', (e3 + 1)) + 1); int e4 = line.indexOf('>', (e3 + 1)); int s5 = (line.indexOf('<', (e4 + 1)) + 1); int e5 = line.indexOf('>', (e4 + 1)); int s6 = (line.indexOf('<', (e5 + 1)) + 1); int e6 = line.indexOf('>', (e5 + 1)); int s7 = (line.indexOf('<', (e6 + 1)) + 1); int e7 = line.indexOf('>', (e6 + 1)); lcd.setCursor(0, 0); lcd.print(line.substring(s1, e1)); //TID lcd.setCursor(0, 1); lcd.print(line.substring(s2, e2)); //Dest lcd.setCursor(14, 1); lcd.print(line.substring(s3, e3)); //Tid lcd.setCursor(0, 2); lcd.print(line.substring(s4, e4)); //Dest lcd.setCursor(14, 2); lcd.print(line.substring(s5, e5)); //Tid lcd.setCursor(0, 3); lcd.print(line.substring(s6, e6)); //Dest lcd.setCursor(14, 3); lcd.print(line.substring(s7, e7)); //Tid ESP.deepSleep(30e6); } } } Logga in eller registrera dig för att kunna kommentera
--file-- New <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $url = "http://api.sl.se/api2/realtimedeparturesV4.xml?key=--API_NYCKEL--&siteid=--STATION--&timewindow=60"; $xml = simplexml_load_file($url); //print_r($xml); $json = json_encode($xml); $array = json_decode($json,TRUE); echo("< "); echo(substr($array["ResponseData"]["LatestUpdate"],11,16)); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["0"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["0"]["DisplayTime"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["1"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["1"]["DisplayTime"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["2"]["Destination"]." "); echo("><"); echo($array["ResponseData"]["Trams"]["Tram"]["2"]["DisplayTime"]." "); print_r(">|"); ?> Logga in eller registrera dig för att kunna kommentera
ESP8266 + LCD 20x4
New#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 20, 4);
const char* ssid = "--name--"; const char* password = "--pw--";
const char* host = "--url--"; const int httpPort = 80; String line; String url = "--file--"; boolean valid = false; void setup() { lcd.begin(20, 4); lcd.init(); lcd.backlight(); lcd.setCursor(0, 0);
WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); } lcd.print("Wifi connected!"); lcd.setCursor(0, 1); lcd.print(WiFi.localIP()); }
void loop() { lcd.clear();
WiFiClient client;
lcd.setCursor(0, 0);
if (!client.connect(host, httpPort)) { lcd.print("fail"); valid = false; } else { lcd.print("OK"); valid = true; }
if (valid) { client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n"); delay(1000);
while (client.available()) { line = client.readStringUntil('|'); }
int s1 = (line.indexOf('<') + 1); int e1 = line.indexOf('>'); if (line.substring(s1, e1)) { int s2 = (line.indexOf('<', (e1 + 1)) + 1); int e2 = line.indexOf('>', (e1 + 1));
int s3 = (line.indexOf('<', (e2 + 1)) + 1); int e3 = line.indexOf('>', (e2 + 1));
int s4 = (line.indexOf('<', (e3 + 1)) + 1); int e4 = line.indexOf('>', (e3 + 1));
int s5 = (line.indexOf('<', (e4 + 1)) + 1); int e5 = line.indexOf('>', (e4 + 1));
int s6 = (line.indexOf('<', (e5 + 1)) + 1); int e6 = line.indexOf('>', (e5 + 1));
int s7 = (line.indexOf('<', (e6 + 1)) + 1); int e7 = line.indexOf('>', (e6 + 1));
lcd.setCursor(0, 0); lcd.print(line.substring(s1, e1)); //TID
lcd.setCursor(0, 1); lcd.print(line.substring(s2, e2)); //Dest lcd.setCursor(14, 1); lcd.print(line.substring(s3, e3)); //Tid
lcd.setCursor(0, 2); lcd.print(line.substring(s4, e4)); //Dest lcd.setCursor(14, 2); lcd.print(line.substring(s5, e5)); //Tid
lcd.setCursor(0, 3); lcd.print(line.substring(s6, e6)); //Dest lcd.setCursor(14, 3); lcd.print(line.substring(s7, e7)); //Tid
ESP.deepSleep(30e6); } } }
--file--
New<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$url = "http://api.sl.se/api2/realtimedeparturesV4.xml?key=--API_NYCKEL--&siteid=--STATION--&timewindow=60";
$xml = simplexml_load_file($url);
//print_r($xml);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
echo("< ");
echo(substr($array["ResponseData"]["LatestUpdate"],11,16));
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["0"]["Destination"]." ");
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["0"]["DisplayTime"]." ");
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["1"]["Destination"]." ");
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["1"]["DisplayTime"]." ");
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["2"]["Destination"]." ");
echo("><");
echo($array["ResponseData"]["Trams"]["Tram"]["2"]["DisplayTime"]." ");
print_r(">|");
?>
(Inget ämne)
New