diff options
Diffstat (limited to 'wifi.c')
-rw-r--r-- | wifi.c | 85 |
1 files changed, 74 insertions, 11 deletions
@@ -36,11 +36,6 @@ /* ---------------------------------------- PRIVATE ROUTINES */ -static WifiStatus ConnectToModem(void) -{ - return eWifiTimeout; -} - static WifiStatus SendToModem(const char *buffer, size_t len) { while(len) @@ -59,6 +54,11 @@ static WifiStatus SendToModem(const char *buffer, size_t len) return eWifiOK; } +static WifiStatus ConnectToModem(void) +{ + return eWifiTimeout; +} + static void Copy(const char *from, const char *to, char *buff, size_t maxlen) { while(maxlen && ((to && from != to) || (!to && *from))) @@ -142,9 +142,67 @@ static int ParseURL(const char *url, strcpy(path, "/"); } + if (!hostname[0]) + { + return 0; + } + return 1; } +static void Chomp(char *p) +{ + size_t l = strlen(p); + + while(l && (p[l - 1] == '\r' || p[l - 1] == '\n')) + { + p[--l] = 0; + } +} + +static WifiStatus ReadLine(char *buff, size_t maxlen) +{ + size_t len = 0; + WifiStatus status; + unsigned char c; + + while(len < maxlen && ((status = GetByte(&c)) == eWifiOK)) + { + buff[len++] = c; + buff[len] = 0; + + if (len > 1) + { + if (buff[len - 1] == '\n' && buff[len - 2] == '\r') + { + Chomp(buff); + return eWifiOK; + } + } + } + + return eWifiFailedToReceive; +} + +static WifiStatus SendATCommand(const char *command) +{ + char line[80]; + + WifiStatus status; + + if((status = SendToModem(command, strlen(command))) != eWifiOK) + { + return status; + } + + if((status = ReadLine(line, sizeof line)) != eWifiOK) + { + return status; + } + + return strcmp("OK", line) == 0 ? eWifiOK : eWifiFailedToSendCommand; +} + /* ---------------------------------------- PUBLIC ROUTINES */ @@ -153,18 +211,23 @@ WifiStatus WifiConnect(void) return ConnectToModem(); } -WifiStatus ConnectURL(const char *method, const char *url) +WifiStatus ConnectURL(int is_post, const char *url, size_t *content_length) { char hostname[MAX_HOSTNAME_LEN]; char path[MAX_PATH_LEN]; int port; int ssl; - WifiStatus status = ParseURL(url, hostname, path, &port, &ssl); + WifiStatus status; - printf("hostname='%s'\n", hostname); - printf("path='%s'\n", path); - printf("port=%d\n", port); - printf("ssl=%d\n", ssl); + if (!ParseURL(url, hostname, path, &port, &ssl)) + { + return eWifiInvalidURL; + } + + if ((status = SendATCommand("AT+CIPMUX=0\r\n")) != eWifiOK) + { + return status; + }` return eWifiTimeout; } |