浏览代码

Updates to UI

Min 6 年之前
父节点
当前提交
c5d7571882
共有 1 个文件被更改,包括 47 次插入6 次删除
  1. 47 6
      tracker.cpp

+ 47 - 6
tracker.cpp

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