-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutft-http-example.ino
170 lines (133 loc) · 4.22 KB
/
utft-http-example.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
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include "SPI.h"
#include "UTFT.h"
// wire it up like this
// https://i.ytimg.com/vi/z5QxTDmKr9Y/maxresdefault.jpg
// esp board for arduino ide, v2, might be in boards manager too if not here it is
// https://github.com/esp8266/Arduino
// UTFT ported to the esp board, needs 1.6.5~6 to work, i'm using 1.6.5
// https://github.com/gnulabis/UTFT-ESP8266
// thanks to this good citizen
// http://www.avrfreaks.net/forum/display-raw-bitmap-image-tft
// utft online converter for your images, awesome.
// http://www.rinkydinkelectronics.com/t_imageconverter565.php
// 1. assemble hardware
// 2. install esp8266 board for arduino ide (after installing arduino ide)
// 3. try a utft demo sketch out, use pins below
// This will make a http connection on port 80 to the server defined below
// It will load ident-1.raw and then ident-2.raw until it receives a 404, when it will then load 1 the next loop
// YMMV I used apache2 so if your headers are oddly different then fix that
UTFT myGLCD ( ILI9341_S5P, 13, 14, 5, 3, 2 );
extern uint8_t SmallFont[];
char ssid[] = "yourSSIDhere";
char pass[] = "supersecretpassword";
int status = WL_IDLE_STATUS;
char server[] = "192.168.1.1"; // http server
char ident[] = "tap1"; // this is the prefix to my raw files
WiFiClient client;
void printWifiStatus() {
// print SSID
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
myGLCD.print("Connected to WiFi", LEFT, 18);
// print IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
int counter = 1;
void connectServer() {
if (client.connect(server, 80)) {
Serial.print("OK TCP session to ");
// myGLCD.print("Connecting to webserver", LEFT, 1);
Serial.println(server);
client.print("GET /");
client.print(ident);
client.print("-");
client.print(counter);
client.print(".raw");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
myGLCD.InitLCD();
myGLCD.InitLCD(PORTRAIT);
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.setColor(255, 255, 255);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("INFO Connecting to SSID: ");
Serial.println(ssid);
myGLCD.print("Connecting to WiFi", LEFT, 1);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait for connection:
delay(3500);
}
Serial.println("OK Connected to WiFi");
printWifiStatus();
}
void loop() {
// delay(10000);
Serial.println("OK Starting loop");
connectServer();
delay(1000);
int breaks = 0;
while (client.available()) {
if (breaks < 2) {
String c = client.readStringUntil('\n');
if (c == "\r") {
breaks++;
} else if (c == "Connection: close\r") {
breaks++;
breaks++;
} else if (c == "HTTP/1.1 404 Not Found\r") {
counter = 0;
breaks++;
breaks++;
} else {
Serial.print("HEADER: ");
Serial.println(c);
}
} else {
uint16_t buf[240];
cbi(myGLCD.P_CS, myGLCD.B_CS);
for (int y = 1; y < 320-1 && client.available(); y++) {
myGLCD.setXY(1, y, 239 , y);
for (int x = 0; x < 240; x++) {
byte l = client.read();
byte h = client.read();
buf[x] = l * 256 + h; // store one line of bits
}
// for (int x = 320; x > 0; x--) { // reverse the bits for landscape - 320.
for (int x = 0; x < 240; x++) { // portrait - 240.
myGLCD.LCD_Write_DATA((buf[x] >> 8),buf[x]);
delay(0);
}
}
sbi(myGLCD.P_CS, myGLCD.B_CS);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println("");
Serial.println("OK Disconnecting from server.");
client.stop();
}
}
delay(15000);
Serial.println("OK Ended loop");
counter++;
}