|
@@ -12,12 +12,12 @@
|
|
|
void setup();
|
|
void setup();
|
|
|
void loop();
|
|
void loop();
|
|
|
|
|
|
|
|
-char ssid[] = "";
|
|
|
|
|
-char pass[] = "";
|
|
|
|
|
|
|
+char ssid[255] = {0};
|
|
|
|
|
+char pass[255] = {0};
|
|
|
|
|
|
|
|
uint16_t ID = 1050; // Device ID
|
|
uint16_t ID = 1050; // Device ID
|
|
|
uint16_t port = 9000;
|
|
uint16_t port = 9000;
|
|
|
-IPAddress server(192,168,0,10);
|
|
|
|
|
|
|
+IPAddress server(192,168,30,1);
|
|
|
WiFiClient wclient;
|
|
WiFiClient wclient;
|
|
|
|
|
|
|
|
uint8_t aes_key[16] = {
|
|
uint8_t aes_key[16] = {
|
|
@@ -35,6 +35,38 @@ typedef struct {
|
|
|
uint8_t AESData[MLEN], *AESResult, AESResult2[MLEN];
|
|
uint8_t AESData[MLEN], *AESResult, AESResult2[MLEN];
|
|
|
uint32_t AESDataLength=MLEN;
|
|
uint32_t AESDataLength=MLEN;
|
|
|
|
|
|
|
|
|
|
+void setupWifi() {
|
|
|
|
|
+ if(ssid[0] != 0x00) return;
|
|
|
|
|
+ int32_t pnt = 0;
|
|
|
|
|
+ bool typingp = false;
|
|
|
|
|
+ Serial.print("SSID: ");
|
|
|
|
|
+ while (1) {
|
|
|
|
|
+ if(Serial.available() > 0) {
|
|
|
|
|
+ if(!typingp) {
|
|
|
|
|
+ ssid[pnt] = Serial.read();
|
|
|
|
|
+ if(ssid[pnt] == 13) {
|
|
|
|
|
+ ssid[pnt] = 0x00;
|
|
|
|
|
+ typingp = true;
|
|
|
|
|
+ pnt = -1;
|
|
|
|
|
+ Serial.println();
|
|
|
|
|
+ Serial.print("PASS: ");
|
|
|
|
|
+ }
|
|
|
|
|
+ else Serial.write(ssid[pnt]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pass[pnt] = Serial.read();
|
|
|
|
|
+ if(pass[pnt] == 13) {
|
|
|
|
|
+ pass[pnt] = 0x00;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ else Serial.write(pass[pnt]);
|
|
|
|
|
+ }
|
|
|
|
|
+ pnt ++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Serial.println();
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void setup() {
|
|
void setup() {
|
|
|
// initialising
|
|
// initialising
|
|
|
Serial.begin(9600);
|
|
Serial.begin(9600);
|
|
@@ -47,6 +79,7 @@ void setup() {
|
|
|
AESSetup(AES_KEY_128BIT, aes_key);
|
|
AESSetup(AES_KEY_128BIT, aes_key);
|
|
|
Serial.println("OK");
|
|
Serial.println("OK");
|
|
|
|
|
|
|
|
|
|
+ setupWifi();
|
|
|
Serial.print("Setup WiFi ..");
|
|
Serial.print("Setup WiFi ..");
|
|
|
WiFi.begin(ssid, pass);
|
|
WiFi.begin(ssid, pass);
|
|
|
while (WiFi.status() != WL_CONNECTED) {delay(200);}
|
|
while (WiFi.status() != WL_CONNECTED) {delay(200);}
|
|
@@ -117,22 +150,30 @@ void send() {
|
|
|
wclient.write((uint8_t *) &h, sizeof(h));
|
|
wclient.write((uint8_t *) &h, sizeof(h));
|
|
|
wclient.write(res, (uint16_t) resLen);
|
|
wclient.write(res, (uint16_t) resLen);
|
|
|
free(res);
|
|
free(res);
|
|
|
|
|
+ memset(buffer, 0x00, 32);
|
|
|
bufferPnt = 0;
|
|
bufferPnt = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
void loop() {
|
|
|
while (Serial.available() > 0) {
|
|
while (Serial.available() > 0) {
|
|
|
uint8_t val = Serial.read();
|
|
uint8_t val = Serial.read();
|
|
|
- Serial.write(val); // echo
|
|
|
|
|
- if ((val == 8 || val == 127) && bufferPnt > 0) {
|
|
|
|
|
|
|
+ if ((val == 8 || val == 127 || val == 27) && bufferPnt > 0) {
|
|
|
bufferPnt--;
|
|
bufferPnt--;
|
|
|
|
|
+ Serial.write(val); // echo
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (val == 26 && buffer[bufferPnt] != 0x00) {
|
|
|
|
|
+ bufferPnt++;
|
|
|
|
|
+ Serial.write(val); // echo
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if(val == 13) {
|
|
if(val == 13) {
|
|
|
send();
|
|
send();
|
|
|
|
|
+ Serial.println();
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- if(bufferPnt >= 255) send();
|
|
|
|
|
|
|
+ Serial.write(val); // echo
|
|
|
|
|
+ if(bufferPnt >= 32) send();
|
|
|
buffer[bufferPnt] = val;
|
|
buffer[bufferPnt] = val;
|
|
|
bufferPnt++;
|
|
bufferPnt++;
|
|
|
}
|
|
}
|