-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinterWallet.ino
176 lines (143 loc) · 3.88 KB
/
MinterWallet.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#define _DEBUG_
#ifdef _DEBUG_
#include <Streaming.h> // http://arduiniana.org/libraries/streaming/
#endif
//#define LCD2040
#define LCD128X64
#ifdef LCD128X64
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, D1, D2);
#endif
#include "BTCSECURE_Minter_128x64.h"
#define DEMO_DURATION 5000
long timeSinceLastModeSwitch = 0;
// #define _COIN_MAX_DISPLAY 10
#if defined(ARDUINO_ESP8266_NODEMCU)
// ARDUINO_ESP8266_NODEMCU
#endif
#if defined(ESP8266)
// ESP8266
#endif
// #include <gmpxx.h>
#include "minterapi.h"
#if defined(ARDUINO)
// #include "Arduino.h"
#else
#define String std::string
#define Serial std::cout
#define endl std::endl
#endif
// #define ASYNC_TCP_SSL_ENABLED 1
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#define TRIGGER_PIN D3
// #include <ESP8266mDNS.h>
// #include "ESPAsyncTCP.h"
// #include "SyncClient.h"
MinterApi minterApi("minter-msk.interchain.zone", 80);
#include "printminter.h"
PrintMinter printMinter;
String walletAddress;
void setup()
{
// MinterApi minterApi("https://minter-node-2.testnet.minter.network:8841");
Serial.begin(115200);
Serial.println("test_Minter_LCD v0.0.6");
// pinMode(TRIGGER_PIN, INPUT);
pinMode(TRIGGER_PIN, INPUT_PULLUP);
#ifdef LCD128X64
display.init();
display.flipScreenVertically();
display.clear();
display.clear();
drawBMImage();
display.display();
#endif
walletAddress = "Mx0903ab168597a7c86ad0d4b72424b3632be0af1b";
String ssid = String(WiFi.SSID());
// String pass = WiFi.psk();
if (WiFi.waitForConnectResult() != WL_CONNECTED)
{
#ifdef _DEBUG_
Serial << "WiFi Failed!" << endl;
#endif
}
#ifdef LCD128X64
#endif
#ifdef _DEBUG_
Serial << "WiFi ssid: " << ssid << ", pass:****** , ip:" << WiFi.localIP() << endl;
#endif
}
void displayCoins(Wallet &wallet, const int16_t startY = 0)
{
uint16_t length = wallet.balance.length();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
for (uint16_t i = 0; i < length; i++)
{
const int16_t y = startY + (i * 11);
const String strCoin = wallet.balance.at(i).coin;
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, y, strCoin);
display.drawString(75, y, String(wallet.balance.at(i).amount, 4));
#ifdef __DEBUG_ // #endif
Serial
<< "coin: " << strCoin
<< ", amount: " << wallet.balance.at(i).amount
<< ", amountStr: " << wallet.balance.at(i).amountStr
<< endl;
#endif
}
}
void drawBMImage()
{
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
display.drawXbm(0, 0, BM_Logo_width, BM_Logo_height, BM_Logo_bits);
}
void loop()
{
if (digitalRead(TRIGGER_PIN) == LOW)
{
WiFiManager wifiManager;
//wifiManager.resetSettings();
// WiFi.mode(WIFI_STA);
if (!wifiManager.startConfigPortal("OnDemandAP"))
{
#ifdef _DEBUG_ // #endif
Serial.println("failed to connect and hit timeout");
#endif
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
#ifdef _DEBUG_ // #endif
Serial.println("connected...yeey :)");
#endif
}
if (millis() - timeSinceLastModeSwitch > DEMO_DURATION)
{
timeSinceLastModeSwitch = millis();
Wallet wallet;
String MxStr = printMinter.Mx(walletAddress);
if (minterApi.getAddress(walletAddress, 0, wallet) == MINTERAPI_OK)
{
#ifdef __DEBUG_ // #endif
minterApi.printWallet(wallet, "main ");
#endif
display.clear();
displayCoins(wallet, 15);
}
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 0, MxStr);
display.display();
}
// counter++;
// delay(10);
}