· 5 years ago · Feb 07, 2021, 11:30 AM
1/**
2
3 DEXTERPAGER P2000 reader !
4 Made for TTGo esp32 having TFT !
5 6-2-2021 made by DexterBot
6 it has 3 API servers having different outputs to show ,
7 now all P2000 pager server ,
8 use thingspeak.com to make a web page you like in 2 a API
9 so you could use the data to show on your Dexterpager
10*/
11#define DEBUG 0 // 1 enable 0 disable (DEBUG) for serial output 115200 baud //
12////////////////// setup your wifi here //////////////////
13#define APPNAME "********" //Acces point name
14#define WPAKEY "********" // WPA KEY
15///////////////////////////////////////////////////////////
16#include <Arduino.h>
17#include "pagerimg.h"
18#include "siren.h"
19#include <WiFi.h>
20#include <WiFiMulti.h>
21#include <HTTPClient.h>
22WiFiMulti wifiMulti;
23#include <SPI.h>
24#include <TFT_eSPI.h> // Hardware-specific library
25TFT_eSPI tft = TFT_eSPI();
26uint8_t selector1 = 0;
27uint8_t selector2 = 0;
28String checker; // new stuff i try //
29///////////////////////////////////////////////////////////////////////////////////////////////////
30#define SERVERAPI1 "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=12BB7OMBEIN3IIJJ"
31#define SERVERAPI2 "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=Y8PWPLDACM1J84EQ"
32#define SERVERAPI3 "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=NVP6DSJDGEYPGZ22"
33#define TimeServer "https://api.thingspeak.com/apps/thinghttp/send_request?api_key=BZOJWIRDNJ6GAMM6"
34//#define LED_PIN 21
35
36void setup() {
37 pinMode(0, INPUT_PULLUP);
38 pinMode(35, INPUT_PULLUP);
39 // pinMode(LED_PIN, OUTPUT);
40 if (DEBUG == 1) Serial.begin(115200);
41 tft.init();
42 tft.fillScreen(TFT_BLACK);
43 tft.setRotation(3);
44 tft.setTextFont(2);
45 tft.setTextColor(TFT_GREEN);
46 tft.drawString(" P2000 RX ", 70, 15);
47 tft.setTextColor(TFT_YELLOW);
48 tft.setTextFont(4);
49 tft.drawString(" Made by dexterbot", 10, 50);
50 tft.setTextColor(TFT_RED);
51 tft.setTextFont(1);
52 tft.drawString(" version 1.01", 66, 100);
53 delay (2000);
54 tft.setSwapBytes(true);
55 tft.pushImage(0, 0, 240, 137, pager);
56 for (uint8_t t = 4; t > 0; t--) {
57 if (DEBUG == 1) Serial.flush();
58 tft.setTextColor(TFT_CYAN);
59 tft.setCursor(50, 30);
60 tft.printf("SYSTEM STARTING %d...\n", t);
61 delay(1000);
62 tft.pushImage(0, 0, 240, 137, pager);
63 }
64 tft.setTextColor(TFT_CYAN);
65 tft.setCursor(59, 30);
66 tft.printf("! SYSTEM LOADING !");
67 tft.setTextColor(TFT_GREEN);
68 tft.setCursor(177, 49);
69 tft.printf("!");
70 delay(1000);
71 wifiMulti.addAP(APPNAME, WPAKEY);
72 tft.pushImage(0, 0, 240, 137, pager);
73 tft.setTextColor(TFT_CYAN);
74 tft.setCursor(64, 30);
75 tft.printf("! SYSTEM OK !");
76 delay(1000);
77}
78/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
79/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80void loop() {
81 if (digitalRead(35) == 0) selector1 = 1;
82 if (selector1 == 1) {
83 gettime();
84 getmesage();
85 delay(7000);
86 selector1 = 0;
87 }
88 else if (selector1 == 0) {
89 gettime();
90 }
91 if (digitalRead(0) == 0) {
92 tft.fillScreen(TFT_BLACK);
93 tft.setTextColor(TFT_YELLOW);
94 tft.setTextFont(4);
95 tft.drawString("SELECT SERVER", 10, 50);
96 selector2 = selector2 + 1;
97 if (selector2 > 2 )selector2 = 0;
98 if (selector2 == 0 ) tft.drawString("SERVER 1", 10, 80);
99 if (selector2 == 1 ) tft.drawString("SERVER 2", 10, 80);
100 if (selector2 == 2 ) tft.drawString("SERVER 3", 10, 80);
101 delay(1000);
102 }
103 tft.pushImage(0, 0, 240, 137, pager);
104 tft.setTextColor(TFT_YELLOW);
105 tft.setCursor(170, 52);
106 tft.printf("<<");
107 tft.setTextFont(2);
108 tft.setTextColor(TFT_CYAN);
109 tft.setCursor(50, 30);
110 tft.printf("! PUSH BUTTON !");
111 delay(100);
112 tft.pushImage(0, 0, 240, 135, pager);
113 tft.setTextColor(TFT_CYAN);
114 tft.setCursor(38, 30);
115 tft.printf("! WAITING FOR DATA !");
116 delay(100);
117}
118//////////////////////////////////////////////////////////////
119/////////////////////////////////////////////////////////////////////////////////////////
120/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121void gettime() {
122 tft.setTextColor(TFT_YELLOW);
123 if (selector1 == 1) {
124 tft.fillScreen(TFT_BLACK);
125 tft.setTextColor(TFT_YELLOW);
126 }
127 if ((wifiMulti.run() == WL_CONNECTED)) {
128 if (selector1 == 0) {
129 tft.setCursor(166, 48);
130 tft.printf("<<<");
131 tft.setTextColor(TFT_CYAN);
132 }
133 HTTPClient http;
134 http.begin(TimeServer);
135 int httpCode = http.GET();
136 String payload = http.getString();
137 char buf[1000];
138 payload.toCharArray(buf, 1000);
139 String tmp2 = buf ;
140 ///////////////////////////////////////////////////////////////////
141 tmp2.trim();
142 if (selector1 == 1) {
143 tft.setCursor(3, 19);
144 tft.drawLine(0, 10, 239, 10, TFT_RED);
145 tft.drawLine(0, 40, 239, 40, TFT_RED);
146 }
147 if (selector1 == 0) tft.setCursor(34, 52);
148 tft.setTextFont(1);
149 tft.println(tmp2);
150 if (DEBUG == 1) Serial.println(tmp2);
151 http.end();
152 if (selector1 == 0)delay(3000);
153 }
154}
155
156void getmesage() {
157 if ((wifiMulti.run() == WL_CONNECTED)) {
158 tft.setTextColor(TFT_YELLOW);
159 HTTPClient http;
160 if (DEBUG == 1) Serial.print("[HTTP] begin...\n");
161 if (selector2 == 0 ) http.begin (SERVERAPI1);// 3 different API inputs //
162 if (selector2 == 1 ) http.begin(SERVERAPI2); //
163 if (selector2 == 2 )http.begin(SERVERAPI3); //
164 int httpCode = http.GET();
165 String payload = http.getString();
166 char buf[1000];
167 payload.toCharArray(buf, 1000);
168 String tmp2 = buf ;
169 if (checker == tmp2) { // checks if messages are the same ,//
170 tft.setTextColor(TFT_YELLOW);
171 tft.setCursor(54, 60);
172 tft.printf("! NO NEW MESSAGES !");
173 return;
174 }
175 if (checker != tmp2)checker = tmp2; // new stuff i try //
176 ///////////////////////////////////////////////////////////////////
177 if (selector2 != 0 )tft.pushImage(200, 80, 30, 28, light);
178 if (selector2 == 0 )tft.pushImage(200, 40, 30, 28, light);
179 tmp2.trim();
180 tft.setCursor(0, 50);
181 if (selector2 == 0 ) tft.setTextFont(1);
182 if (selector2 == 1 ) tft.setTextFont(2);
183 if (selector2 == 2 ) tft.setTextFont(2);
184 tft.println(tmp2);
185 if (DEBUG == 1) Serial.println(tmp2);
186 http.end();
187 tft.setTextFont(1);
188 selector1 = 0;
189 }
190}
191