15
15
16
16
// #define MAX7219DISPLAY // uncomment if using MAX7219-4-digit-display-for-ESP8266
17
17
#ifdef MAX7219DISPLAY
18
- #include < SPI.h>
19
- #include < bitBangedSPI.h>
20
- #include < MAX7219_Dot_Matrix.h> // https://github.com/SensorsIot/MAX7219-4-digit-display-for-ESP8266
18
+ #include < SPI.h>
19
+ #include < bitBangedSPI.h>
20
+ #include < MAX7219_Dot_Matrix.h> // https://github.com/SensorsIot/MAX7219-4-digit-display-for-ESP8266
21
+ // VCC -> 5V, GND -> GND, DIN -> D7, CS -> D8 (configurable below), CLK -> D5
22
+ const byte chips = 4 ; // Number of Display Chips
23
+ MAX7219_Dot_Matrix display (chips, D8); // Chips / LOAD
24
+ unsigned long MOVE_INTERVAL = 20 ; // (msec) increase to slow, decrease to fast
21
25
#endif
22
26
23
27
bool resetsettings = false ; // true to reset WiFiManager & delete FS files
@@ -34,12 +38,6 @@ unsigned long twi_update_interval = 20; // (seconds) minimum 5s (180 API calls
34
38
static char const accesstoken[] = " 041657084136508135-F3BE63U4Y6b346kj6bnkdlvnjbGsd3V" ;
35
39
static char const accesstoken_sec[] = " bsekjH8YT3dCWDdsgsdHUgdBiosesDgv43rknU4YY56Tj" ;
36
40
#endif
37
- #ifdef MAX7219DISPLAY
38
- // VCC -> 5V, GND -> GND, DIN -> D7, CS -> D8 (configurable below), CLK -> D5
39
- const byte chips = 4 ; // Number of Display Chips
40
- MAX7219_Dot_Matrix display (chips, D8); // Chips / LOAD
41
- unsigned long MOVE_INTERVAL = 20 ; // (msec) increase to slow, decrease to fast
42
- #endif
43
41
#ifndef AutoAP_password
44
42
#define AutoAP_password " password" // Dafault AP Password
45
43
#endif
@@ -201,6 +199,53 @@ void extractJSON(String tmsg) {
201
199
delete [] msg2;
202
200
}
203
201
202
+ void extractTweetText (String tmsg) {
203
+ unsigned int msglen = tmsg.length ();
204
+
205
+ String seatchstr = " ,\" text\" :\" " ;
206
+ unsigned int searchlen = seatchstr.length ();
207
+ int pos1 = -1 , pos2 = -1 ;
208
+ for (int i=0 ; i <= msglen - searchlen; i++) {
209
+ if (tmsg.substring (i,searchlen+i) == seatchstr) {
210
+ pos1 = i + searchlen;
211
+ break ;
212
+ }
213
+ }
214
+ seatchstr = " \" ,\" " ;
215
+ searchlen = seatchstr.length ();
216
+ for (int i=pos1; i <= msglen - searchlen; i++) {
217
+ if (tmsg.substring (i,searchlen+i) == seatchstr) {
218
+ pos2 = i;
219
+ break ;
220
+ }
221
+ }
222
+ String text = tmsg.substring (pos1, pos2);
223
+
224
+ seatchstr = " ,\" screen_name\" :\" " ;
225
+ searchlen = seatchstr.length ();
226
+ int pos3 = -1 , pos4 = -1 ;
227
+ for (int i=pos2; i <= msglen - searchlen; i++) {
228
+ if (tmsg.substring (i,searchlen+i) == seatchstr) {
229
+ pos3 = i + searchlen;
230
+ break ;
231
+ }
232
+ }
233
+ seatchstr = " \" ,\" " ;
234
+ searchlen = seatchstr.length ();
235
+ for (int i=pos3; i <= msglen - searchlen; i++) {
236
+ if (tmsg.substring (i,searchlen+i) == seatchstr) {
237
+ pos4 = i;
238
+ break ;
239
+ }
240
+ }
241
+ String usert = " @" + tmsg.substring (pos3, pos4);
242
+
243
+ if (text.length () >0 ) {
244
+ text = usert + " says " + text;
245
+ search_msg = std::string (text.c_str (), text.length ());
246
+ }
247
+ }
248
+
204
249
void updateDisplay (){
205
250
char *msg = new char [search_msg.length () + 1 ];
206
251
strcpy (msg, search_msg.c_str ());
@@ -216,7 +261,7 @@ void updateDisplay(){
216
261
#ifdef MAX7219DISPLAY
217
262
display.sendString (" --------" );
218
263
#endif
219
- extractJSON (tcr.searchTwitter (search_str));
264
+ extractTweetText (tcr.searchTwitter (search_str));
220
265
DEBUG_PRINT (" Search: " );
221
266
DEBUG_PRINTLN (search_str.c_str ());
222
267
DEBUG_PRINT (" MSG: " );
0 commit comments