image downloader working now #21

pull/1/head
Thomas Ballmann 4 years ago
parent 306c829609
commit 16a63b5745

@ -24,16 +24,22 @@ void display_time();
const char faceCalendarPicutreJson[] = "/calendarPhoto.json"; const char faceCalendarPicutreJson[] = "/calendarPhoto.json";
const char faceCalendarPicture[] = "/calendarPhoto.png"; const char faceCalendarPicture[] = "/calendarPhoto.png";
bool triggerUpdateCalendar = false;
void setupFaceCalendar() void setupFaceCalendar()
{ {
//downloadRandomePicture();
//downloadFile("https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF", "/tom");
} }
void loopFaceCalendar() void loopFaceCalendar()
{ {
//downloadRandomePicture(); if (triggerUpdateCalendar)
//downloadFile("https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF", "/tom"); {
triggerUpdateCalendar = false;
Serial.println("...triggerUpdateCalendar");
downloadRandomePicture();
}
} }
void playlistFaceCalendar() void playlistFaceCalendar()
@ -57,69 +63,20 @@ void showFaceCalendar()
bool downloadRandomePicture() bool downloadRandomePicture()
{ {
// download json file String pictureUrl = "http://sonic/unsplash.php?"; // TODO
Serial.println(" download json"); pictureUrl += "&w=390&h=384"; // size
String randomUrl = "https://api.unsplash.com/photos/random"; pictureUrl += "&fm=png"; // format
randomUrl += "&client_id=6cb16f348161f1c3e6bf21172c398893beec2d8d3ccf740bff4e72feac507422";
if (true) // downloadFile(randomUrl, faceCalendarPicutreJson)
{
Serial.println(" read json");
File file = SPIFFS.open(faceCalendarPicutreJson);
if (!file)
{
Serial.print("Failed to open file: ");
Serial.println(faceCalendarPicutreJson);
return false;
}
StaticJsonDocument<5000> docPicutre; // Use arduinojson.org/v6/assistant to compute the capacity.
DeserializationError error = deserializeJson(docPicutre, file);
file.close();
if (error)
{
Serial.print("Failed to read file: ");
Serial.println(faceCalendarPicutreJson);
Serial.println(error.c_str()); return downloadFile(pictureUrl, faceCalendarPicture);
return false;
}
//String pictureUrl = "https://images.unsplash.com/photo-1582910587039-b4f085805c86?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0";
String pictureUrl = docPicutre["urls"]["raw"];
pictureUrl += "&w=390&h=384"; // size
pictureUrl += "&fm=png"; // format
pictureUrl += "&fit=crop"; // crop to needed size
pictureUrl += "&duotone=000000,FFFFFF"; // grayscale to save bytes
downloadFile(pictureUrl, faceCalendarPicture);
return true;
}
return false;
} }
/** /**
* download and update calendar data * download and update calendar data
* @todo is not working
*/ */
bool updateCalendarData() bool updateCalendarData()
{ {
//downloadFile("https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF", "/tom"); triggerUpdateCalendar = true;
//return false; return true;
if (downloadRandomePicture())
{
//readWeatherData();
return true;
}
return false;
} }
void display_calender() void display_calender()

Loading…
Cancel
Save