Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

<img src="https://raw.githubusercontent.com/marc3linho/OrangeClock/main/images/readme/wifi_1.png" width="50%" >

5. Set your wifi credentials and save them, the OrangeClock will reboot automatically and connect to your network
5. Set your wifi credentials and save them, the OrangeClock will reboot automatically and connect to your network.
If you want to use your self-hosted mempool, you can enter the url. Leave it empty to use mempool.space

<img src="https://raw.githubusercontent.com/marc3linho/OrangeClock/main/images/readme/wifi_2.jpg" width="50%" >

Expand All @@ -52,6 +53,7 @@ If you have any questions, problems or suggestions please feel free to contact m
## Known bugs and strange effects

* The wifi credentials are stored in plain text on the Pico, so the OrangeClock should be connected to an isolated network or guest network.
When you want to use your self-hosted mempool make sure that the url is reachable from the network

* Strange effect: The display flickers every 12 hours (The reason is a full refresh).

Expand Down
Binary file modified images/readme/wifi_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions src/ap_templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,26 @@ <h3>v0.2-beta</h3>
<div>
<h2>Network</h2>
<div>
<label for="ssid">SSID</label>
<label for="ssid">SSID*</label>
<input type="text" id="ssid" name="ssid" placeholder="SSID">
</div>
<div style="margin-top:0.5rem;">
<label for="password">Password</label>
<label for="password">Password*</label>
<input type="password" id="password" name="password" placeholder="Password">
</div>
<div style="margin-top:0.5rem;">
<label for="mempool" title="setup with your self-hosted mempool, leave empty to use mempool.space">mempool</label>
<input type="text" id="mempool" name="mempool" placeholder="https://mempool.space">
</div>
<label>*required</label>
</div>
<hr />
<div>
<h2>Layout</h2>
<h3>Line 1</h3>
<div>
<div>
<input type="radio" id="bh" name="line1" value="bh" checked="checked">
<input type="radio" id="bh" name="line1" value="bh" checked>
<label for="mt">Block Time</label>
</div>
<div>
Expand All @@ -57,7 +62,7 @@ <h3>Line 1</h3>
<h3>Line 2</h3>
<div>
<div>
<input type="radio" id="mts" name="line2" value="mts" checked="checked">
<input type="radio" id="mts" name="line2" value="mts" checked>
<label for=mts">Moscow Time (satsymbol icon)</label>
</div>
<div>
Expand All @@ -81,7 +86,7 @@ <h3>Line 2</h3>
<h3>Line 3</h3>
<div>
<div>
<input type="radio" id="fees" name="line3" value="fees" checked="checked">
<input type="radio" id="fees" name="line3" value="fees" checked>
<label for="fees">Transaction Fees</label>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def ap_catch_all(request):

def application_mode():
print("Entering application mode.")
orangeClock.setSecrets(wifi_credentials["ssid"], wifi_credentials["password"])
orangeClock.setSecrets(wifi_credentials["ssid"], wifi_credentials["password"], wifi_credentials["mempool"])
orangeClock.setSelectDisplay(wifi_credentials["line1"], wifi_credentials["npub"], wifi_credentials["line2"])
orangeClock.main()

Expand Down
37 changes: 29 additions & 8 deletions src/orangeClockFunctions/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@


class ExternalData:
def __init__(self, url, ttl=300, json=True):
def __init__(self, url, ttl=300, ignore_ssl_errors=False, json=True):
self.url = url
self.ttl = ttl
self.json = json
self.updated = None
self.stale = None
self.data = None
self.ignore_ssl_errors = ignore_ssl_errors
self.refresh()

def __str__(self):
return 'ExternalData("{}")'.format(self.url)

def get_response(self):
try:
response = requests.get(self.url)
except requests.exceptions.SSLError as ssl_error:
if self.ignore_ssl_errors:
response = requests.get(self.url, verify=False)
else:
raise ssl_error
return response

def refresh(self):
now = time.time()
answer = None
Expand All @@ -24,7 +35,7 @@ def refresh(self):
return answer

try:
response = requests.get(self.url)
response = self.get_response()
if response.status_code == 200:
if self.json:
data = response.json()
Expand Down Expand Up @@ -63,15 +74,25 @@ def refresh(self):
# functions for updating the _extdata singleton
#

def initialize():
def init_mempool_data(mempool_api, ignore_ssl_errors):
_extdata.update({
"prices": ExternalData(f"{mempool_api}/api/v1/prices", 300, ignore_ssl_errors),
"fees": ExternalData(f"{mempool_api}/api/v1/fees/recommended", 120, ignore_ssl_errors),
"height": ExternalData(f"{mempool_api}/api/blocks/tip/height", 180, ignore_ssl_errors, json=False)
})


def initialize(mempool_api):
keys = [x for x in _extdata.keys()]
for key in keys:
del _extdata[key]
_extdata.update({
"prices": ExternalData("https://mempool.space/api/v1/prices", 300),
"fees": ExternalData("https://mempool.space/api/v1/fees/recommended", 120),
"height": ExternalData("https://mempool.space/api/blocks/tip/height", 180, json=False),
})
if not mempool_api:
print("get info from mempool.space ...")
init_mempool_data("https://mempool.space", False)
else:
print("get info from self-hosted mempool ...")
init_mempool_data(mempool_api, True)


def set_nostr_pubkey(npub):
_extdata['zaps'] = ExternalData("https://api.nostr.band/v0/stats/profile/"+npub, 300)
Expand Down
6 changes: 4 additions & 2 deletions src/orangeClockFunctions/displayBlockMoscowFees.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ def setSelectDisplay(displayVersion1, nPub, displayVersion2):
dispVersion2 = displayVersion2


def setSecrets(SSID, PASSWORD):
def setSecrets(SSID, PASSWORD, mempool_url):
global secretsSSID
global secretsPASSWORD
global mempool
secretsSSID = SSID
secretsPASSWORD = PASSWORD
mempool = mempool_url


def getMoscowTime():
Expand Down Expand Up @@ -156,7 +158,7 @@ def main():
connectWIFI()
displayInit()

datastore.initialize()
datastore.initialize(mempool)
if npub:
datastore.set_nostr_pubkey(npub)

Expand Down