Skip to content

Commit

Permalink
Merge branch 'master' into dev-firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
rackrick committed May 22, 2021
2 parents a5c872e + 09f6e73 commit 44108f8
Show file tree
Hide file tree
Showing 21 changed files with 258,609 additions and 14 deletions.
Binary file added CAD/Moonwatch 2.f3z
Binary file not shown.
258,436 changes: 258,436 additions & 0 deletions CAD/Moonwatch 2.stp

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# MoonWatch
# MoonWatch

<img src="docs/Moonwatch.png" alt="Moonwatch"/>

The Moonwatch is a project originating from the Klipper community that tries to realize something similar to the project "Printer Monitor" by Qrome.
It utilizes the moonraker API in order to gather information about your printer's current status and displays them in a comprehensive manner.
Whenever your printer is not running it simply shows a watch.

The goal of the project is to make for an easy and cheap yet very useful and fun little project for all the Klipper lovers out there!

It has to be noted that this project is still in development and therefore everything is subject to change.

***

How to setup your watch see the [getting started guide](/docs/GettingStarted.md).

**Note:** Be aware this is an very early software state and there is no guarantee its working without any issues.

# Enjoy!
Binary file added STL/Backplate.stl
Binary file not shown.
Binary file added STL/Enclosure.stl
Binary file not shown.
Binary file added STL/Frontplate.stl
Binary file not shown.
Binary file added STL/LED_Clip.stl
Binary file not shown.
91 changes: 91 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Getting started guide

This document gives an explanation how to setup your own MoonWatch!

## Bill of Materials

- 1,8" TFT SPI Display ST7735 (Support for additonal Displays is coming soon)
- D1 Mini - ESP8266
- Up to 4 WS2812B LEDs
- A few jumper cables and dupont connectors (see wiring)
- 4 pcs of M3x6 screws

## Printlist

- 1 [Frontplate](../STL/Frontplate.stl)
- 1 [Backplate](../STL/Backplate.stl)
- 1 [Enclosure](../STL/Enclosure.stl)
- 1 [Led Clip](../STL/LED_Clip.stl)


**Print settings:**

Nozzle Diameter: 0.4mm<br />
Layer Height: 0.2mm<br />
Print without supports<br />

## Wiring

![Wiring](Moonwatch_Cabling.jpg)

## Software
### Flash firmware

#### Windows guide (*NIX systems follow soon)

In order to flash the software you first need to install the CH340 USB-Driver for the ESP8266.
Download and install it from [https://wemos.cc](https://www.wemos.cc/en/latest/ch340_driver.html). After installing get the [latest release](https://github.com/rackrick/MoonWatch/releases) of MoonWatch. Unzip and run `moonwatch-flash.bat`.

**Warning: This will erase your ESP8266 current memory and will overwrite it with the MoonWatch firmware.**

Enter the COM-Port of your ESP8266 and hit enter twice to start the flashing process.
If you don't know the COM-Port number open the Windows Device Manger -> Ports (COM & LPT) and look for `USB-Serial CH340`.

Is the firmware sucessfully flashed to your ESP8266 the MoonWatch should boot now and display the setup instructions.

### Configuration

As soon the Moonwatch starts it will open the `MoonWatch` wifi network for the initial setup.
Connect with your wifi device of joice to the MoonWatch network and browse to [http://192.168.4.1](http://192.168.4.1).
Enter your wifi network name and password and hit save. The interface should prompt you to reset your Moonwatch to apply the new settings.
After the restart it connects to your own wifi and displays the ip optained from your router.

**Note:** The Configuration Network and the storage of the MoonWatch is not encrypted. Make sure to use MoonWatch in an safe envoirment.

On an successfull connection to your local wifi network. MoonWatch will disable the configuration hotspot and is reachable with the IP displayed on startup.
Use the Interface to add your printers to watch and enjoy your MoonWatch.


## Interface Settings

#### General
- Wifi Network: The SSID / Name of your network
- Wifi Password: Your password goes here
- Display Type: For future use to select the installed display.

#### Printers

Button `Add Printer`: Add a new printer to your configuration<br />
Button `Remove Printer`: Removes the last printer from your configuration

- Printer Name: Display name of your printer.
- Host: Hostname or IP-Adress of your printer.
- Led#: 0 based index of the avaible LEDs. This option defines which LED shows the status of this printer.

#### LED

- Number of LEDs: Sets the number of avaible LEDs on your LED stripe.
- Status Led#: 0 based index of avaible LEDs. This option defines which LED shows the MoonWatch system status.<br />
(0 = LED 1 on the stripe, 1 = LED 2, ...)
- Brightness: Sets the brightness of your LED stripe. 0-255 (0 = off, 255 = max power).

## Troubleshooting

1. Display stays white<br />
Check your wiring.

2. LED stripe is not working<br />
The WS2812B have a direction from where the data shoule be coming. Check the arrow on the stripe.



Binary file added docs/Moonwatch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Moonwatch_Cabling.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Moonwatch_Schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion firmware/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
data/moonwatch.json
2 changes: 2 additions & 0 deletions firmware/data/include/moonwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function updateConfig(data) {
// general settings
document.getElementById("wifi").value = data.general.wifi;
document.getElementById("display").value = data.general.display;
document.getElementById("utcoffset").value = data.general.utcoffset;

// printers
for (let i = 0; i < data.printers.length; i++) {
Expand All @@ -36,6 +37,7 @@ function save() {
wifi: document.getElementById("wifi").value,
password: document.getElementById("password").value,
display: document.getElementById("display").value,
utcoffset: document.getElementById("utcoffset").value,
},
printers: [],
led: {
Expand Down
8 changes: 8 additions & 0 deletions firmware/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ <h2>Welcome to MoonWatch</h2>
(currently only ST7735 Displays are supported)
</td>
</tr>
<tr>
<td class="label">
UTC Offset (Timezone):
</td>
<td class="settings">
<input type="number" id="utcoffset">
</td>
</tr>
<!-- PRINTER SETTINGS -->
<tr>
<td colspan="2" class="headline">Printers</td>
Expand Down
20 changes: 20 additions & 0 deletions firmware/data/moonwatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"general": {
"wifi": "",
"password": "",
"display": 0,
"utcoffset": 2
},
"printers": [
{
"name": "yourprinter",
"host": "moonrakerhost",
"led": 1
}
],
"led": {
"numleds": 5,
"brightness": 10,
"statusled": 0
}
}
19 changes: 15 additions & 4 deletions firmware/src/MoonWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MoonWatch::setupMonitor() {
lcd = DisplayFactory::getInstance(static_cast<RP::eDisplayMode>(config.general.display)); //TODO: from config
String loadMsg[] = {
"MoonWatch",
"V0.2"
"V0.11"
};
lcd->showStatusMsg(loadMsg, 2);
delay(2000);
Expand All @@ -66,7 +66,7 @@ void MoonWatch::setupMonitor() {
String(F("please connect to wifi:")),
String(F("MoonWatch")),
String(F("and browse to")),
String(F("http:\\\\192.168.4.1")),
String(F("http://192.168.4.1")),
String(F("to setup your MoonWatch"))
};

Expand Down Expand Up @@ -230,6 +230,9 @@ void MoonWatch::startMonitor() {
lcd->showPrinterScreen(printerName, printer);
}
} else {
Serial.println("idle screen: " + config.printers[activePrinter].Name);
Serial.println(printer.connectionState);

lcd->showIdleScreen();
leds[printerLed] = CRGB::Black;
}
Expand Down Expand Up @@ -265,26 +268,34 @@ void MoonWatch::startMonitor() {

bool MoonWatch::switchPrinter(std::vector<PrinterConfig> printers) {

Serial.println(F("Try to switch"));

uint nextPrinter = activePrinter;

// with one printer we can't switch
if (printers.size() == 1) {
return false;
}

if (activePrinter < printers.size()) {
if (activePrinter < (printers.size() - 1)) {
nextPrinter++;
} else {
nextPrinter = 0;
}

Serial.println("try next printer " + printers[nextPrinter].Name + "(" + nextPrinter + ")");

MoonrakerClient mrClient;
printer = mrClient.getData(printers[nextPrinter].Host);

if (printer.connectionState == "success") {
activePrinter = nextPrinter;
Serial.println(F("success, switch printer"));
activePrinter = nextPrinter;
return true;
} else {
Serial.println(F("error, printer not reachable. skip."));
leds[printers[nextPrinter].Led] = CRGB::Black;

return false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions firmware/src/Webserver/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ namespace RP {
config.wifi = jsonObj["general"]["wifi"].as<String>();
config.password = jsonObj["general"]["password"].as<String>();
config.display = jsonObj["general"]["display"].as<int>();
config.utcoffset = jsonObj["general"]["utcoffset"].as<int>();
} else {
config.display = jsonObj["general"]["display"].as<int>();
config.utcoffset = jsonObj["general"]["utcoffset"].as<int>();
}

bool updateGeneral = configStore.updateGeneral(config);
Expand Down Expand Up @@ -125,6 +127,7 @@ namespace RP {
// reset esp
server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request){
Serial.println(F("reset called"));
request->send(200, "application/json", "{ \"status\": \"ok\" }");
ESP.reset();
});

Expand Down
10 changes: 6 additions & 4 deletions firmware/src/tools/ConfigStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ namespace RP {
Serial.println(F("error loading file from LittleFs"));
return false;
}



DeserializationError docError = deserializeJson(doc, config);

Serial.println(doc.as<String>());
if (docError) {
Serial.println(F("error parsing json"));
return false;
}

Serial.println("Json:");
Serial.println(doc.as<String>());

// general config
general.wifi = doc["general"]["wifi"].as<String>();
general.password = doc["general"]["password"].as<String>();
general.display = doc["general"]["display"].as<int>();
general.utcoffset = doc["general"]["utcoffset"].as<int>();

// printers array
JsonArray arrPrinters = doc["printers"].as<JsonArray>();
Expand Down Expand Up @@ -69,6 +69,7 @@ namespace RP {
json["general"]["wifi"] = general.wifi;
json["general"]["password"] = general.password;
json["general"]["display"] = general.display;
json["general"]["utcoffset"] = general.utcoffset;

JsonArray arrPrinters = json["printers"].as<JsonArray>();

Expand Down Expand Up @@ -113,6 +114,7 @@ namespace RP {
}

general.display = newConfig.display;
general.utcoffset = newConfig.utcoffset;

return true;
}
Expand Down
1 change: 1 addition & 0 deletions firmware/src/tools/GeneralConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace RP {
String wifi;
String password;
int display;
int utcoffset;
};
}
7 changes: 3 additions & 4 deletions firmware/src/tools/NtpClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace RP {
return instance;
}

//1613519630

String NtpClock::getDateTimeString() {
// tick tack clock
tickTime();
Expand Down Expand Up @@ -67,8 +65,9 @@ namespace RP {
if (!ntpSuccess) {
delay(1000);
}

long utcOffset = 1 * 60 * 60; //TODO: Get from config

ConfigStore& config = ConfigStore::getInstance();
long utcOffset = config.general.utcoffset * 60 * 60;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffset);
timeClient.begin();
Expand Down
5 changes: 5 additions & 0 deletions firmware/src/tools/NtpClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

#ifndef ConfigStoreH
#define ConfigStoreH
#include "ConfigStore.h"
#endif

namespace RP
{
namespace Tools
Expand Down

0 comments on commit 44108f8

Please sign in to comment.