Add some helpful logging and print utilities
This commit is contained in:
parent
8ee6144e34
commit
0670fbc35f
@ -36,13 +36,17 @@ void setup()
|
|||||||
Serial.print("Connected! IP Address: ");
|
Serial.print("Connected! IP Address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
fetchAndDrawImage();
|
// fetchAndDrawImage(clearImage);
|
||||||
|
// fetchAndDrawImage(calibrationImage);
|
||||||
|
fetchAndDrawImage(fetchImage);
|
||||||
|
|
||||||
|
hibernate_and_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fetchAndDrawImage() {
|
void fetchAndDrawImage(const char* url) {
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
|
|
||||||
http.begin(serverName);
|
http.begin(url);
|
||||||
http.setTimeout(40000); // wait up to 40 seconds for response
|
http.setTimeout(40000); // wait up to 40 seconds for response
|
||||||
http.setAuthorization("username", "password");
|
http.setAuthorization("username", "password");
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
@ -65,12 +69,13 @@ void fetchAndDrawImage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
http.end();
|
http.end();
|
||||||
|
|
||||||
hibernate_and_restart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hibernate_and_restart() {
|
void hibernate_and_restart() {
|
||||||
// Go to sleep and wake up later
|
// Go to sleep and wake up later
|
||||||
|
Serial.print("Begining hibernation. Waking up in ");
|
||||||
|
Serial.print(HIBERNATE_TIME_SEC);
|
||||||
|
Serial.println(" seconds");
|
||||||
|
|
||||||
// Configure wake up source as timer
|
// Configure wake up source as timer
|
||||||
esp_sleep_enable_timer_wakeup(HIBERNATE_TIME_SEC * 1000000);
|
esp_sleep_enable_timer_wakeup(HIBERNATE_TIME_SEC * 1000000);
|
||||||
|
@ -103,6 +103,22 @@ func GenerateCalibrationImage(width, height int, colorSpace ColorSpace) []byte {
|
|||||||
return packBytesIntoNibbles(einkImage)
|
return packBytesIntoNibbles(einkImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GenerateClearImage(width, height int, colorSpace ColorSpace) []byte {
|
||||||
|
var einkImage []byte
|
||||||
|
|
||||||
|
// Assume the first color is white
|
||||||
|
// What really matters is that the color is the same for the enitre image
|
||||||
|
clearIndex := 3
|
||||||
|
|
||||||
|
for y := 0; y < height; y++ {
|
||||||
|
for x := 0; x < width; x++ {
|
||||||
|
einkImage = append(einkImage, colorSpace[clearIndex].Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return packBytesIntoNibbles(einkImage)
|
||||||
|
}
|
||||||
|
|
||||||
func packBytesIntoNibbles(input []byte) []byte {
|
func packBytesIntoNibbles(input []byte) []byte {
|
||||||
// input length must divisible by 2
|
// input length must divisible by 2
|
||||||
|
|
||||||
|
@ -68,6 +68,22 @@ func calibrationImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var imageProps ImageProperties
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&imageProps)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := GenerateClearImage(imageProps.Width, imageProps.Height, imageProps.ColorSpace)
|
||||||
|
|
||||||
|
fmt.Printf("Bytes to send: %+v\n", len(data))
|
||||||
|
|
||||||
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
||||||
|
w.Write(data)
|
||||||
|
}
|
||||||
|
|
||||||
func fetchImage(w http.ResponseWriter, r *http.Request) {
|
func fetchImage(w http.ResponseWriter, r *http.Request) {
|
||||||
var imageProps ImageProperties
|
var imageProps ImageProperties
|
||||||
err := json.NewDecoder(r.Body).Decode(&imageProps)
|
err := json.NewDecoder(r.Body).Decode(&imageProps)
|
||||||
@ -130,6 +146,7 @@ func main() {
|
|||||||
// r.Use(basicAuth)
|
// r.Use(basicAuth)
|
||||||
r.Post("/fetchImage", fetchImage)
|
r.Post("/fetchImage", fetchImage)
|
||||||
r.Post("/calibrationImage", calibrationImage)
|
r.Post("/calibrationImage", calibrationImage)
|
||||||
|
r.Post("/clearImage", clearImage)
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println("Started server")
|
fmt.Println("Started server")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user