Giter Site home page Giter Site logo

espaper-server-php's Introduction

espaper-server-php

This repository can be used in conjunction with the espaper-client repository to render content for the ESPaper modules server side. ESPaper modules can be ordered here:

You are supporting the creator of this library.

Introduction

This repository can render JSON objects consumed by ESPaper modules to display information on (e-paper) displays. It also has a built in emulator mode which allows you to preview the results locally before making it available to the ESPaper modules. In this case the code renders SVG instructions instead of espaper-json. This emulation is not 100% adequate but is helpful to quickly see errors before uploading the file to the server.

The scripts in this repository use PHP to render the JSON objects. The parser at https://github.com/squix78/espaper-client just consumes the espaper-json object. As long as it contains valid commands it doesn't care what software created it. This means you could also write a server based on NodeJS, Python, Java or any other language processing an HTTP request and rendering some kind of JSON.

Getting started

The library contains the following files:

  • ESPaperCanvas.php is the library you can use to create espaper-json objects
  • weatherstation.php is a server version of the espaper-weatherstaton. They produce nearly identical results on the espaper-json
  • index.php is called by espaper. You can switch between applications by activating the appropriate include
  • demo.php is some kind of playground

Before we even make the code available to the ESPaper we're going to start a local server to test the scripts. Make sure you have PHP installed and available on your command line tool. Then navigate to the folder of this repository and execute:

php -S localhost:8080

This starts a web server. Then open the following URL in your browser:

http://localhost:8080/index.php?battery=123&output=svg

Do you see the output=svg at the end of the URL? This tells the script to render SVG instead of JSON. By replacing svg with json you can also look at the generated JSON object:

http://localhost:8080/index.php?battery=123&output=json

You can also remove the &output=json completely. Default is to render JSON. If you are happy with the results you can upload this to your php server. Then follow instructions on https://github.com/squix78/espaper-client to get the ESPaper ready.

Font commands

I will add here all the commands later on. For now just let me explain a bit about the font commands. For now all fonts have to be "backed" into the firmware. I am working on a feature which allows you to define new fonts on the server and then download them to the ESPaper. There is a bug in the SDK which causes failure for bigger font files.

espaper-server-php's People

Contributors

squix78 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

espaper-server-php's Issues

$baseUrl is not set before using it in weatherstation.php

$baseUrl is never set but it is used on lines 98-104 in weatherstation.php. The url for the fonts will always be: /fonts/ and the preview doesn't work when you have the php code (and fonts) in a subfolder.

Not sure what the fonts folder needs to be for using it in a real device. Just ordered one and waiting for it to arrive.

Double quotes can mess the json data?

demo.php returns to Mozilla browser:
SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 147 column 24 of the JSON data

It is due to an extra " symbol in JSON payload
"text": "The 2.9" ESPaper Lite and ..."

I'm not sure how to clean this.

And also all <? to change to <?php tags (this for sure is my PHP setup)

License

Could you add license info on this repository please!

Thanks!

Negative temperature issue

Hi, the math needs to be corrected to get valid lines on negative temperatures:
Something like this:

`
function tempToPixel($height, $max, $min, $temp) {
return ($temp - $min) * $height / ($max - $min);
}

for ($i = 0; $i < min(32, sizeof($temps)); $i++) {
$height = tempToPixel(39, $max_temp, $min_temp, $temps[$i]);
$canvas->fillRect(200 + $i * 3, 116 - $height, 2, $height);
}
`

Suggestion: Example of drawing an image?

I notice the MiniGrafx library only supports 24 bit depth which makes this a little more tricky.

The reason I ask is it'll allow for more complex graphics (a graph for example), and time isn't really an issue with an e-ink display.

[edit]
It may be moot if the client cannot store the image at 'native' resolution of the espaper - only other way to do it would be to stream the bmp to the esp and render on the fly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.