Esp8266 работает с AT + командами.Поэтому я пытаюсь создать очень простой сервер для общения.Мой первый вопрос: могу ли я создать базу данных в качестве веб-сервера?А esp8266 связываться напрямую с моей базой данных с помощью запросов?Допустим, я буду использовать mySql.Второй вопрос, если мне нужно сначала связаться с веб-сервером, используя c #, как я могу создать локальный сервер на моем компьютере, который может принимать и отправлять запросы?
Вот пример того, что я посылаю с esp8266
AT+CIPSEND=4,46\r\n
AT+CIPMUX=1\r\n
AT+CIPSTART=4,"TCP","192.168.0.214",5000\r\n
GET / HTTP/1.1\r\nHost: http://localhost:5000/\r\n
AT+CIPCLOSE=4\r\n
Я не знаю, как начать с этого.Я спрашиваю на форуме, потому что я пытаюсь найти простой способ сделать это.
Также я нашел этот пример.Но как мне совместить его для отправки запроса и ответа от клиента?
static void Main(string[] args)
{
Console.WriteLine("Starting server...");
_httpListener.Prefixes.Add("http://localhost:5000/"); // add prefix "http://localhost:5000/"
_httpListener.Start(); // start server (Run application as Administrator!)
Console.WriteLine("Server started.");
Thread _responseThread = new Thread(ResponseThread);
_responseThread.Start(); // start the response thread
}
static void ResponseThread()
{
while (true)
{
HttpListenerContext context = _httpListener.GetContext(); // get a context
// Now, you'll find the request URL in context.Request.Url
byte[] _responseArray = Encoding.UTF8.GetBytes("<html><head><title>Localhost server -- port 5000</title></head>" +
"<body>Welcome to the <strong>Localhost server</strong> -- <em>port 5000!</em></body></html>"); // get the bytes to response
context.Response.OutputStream.Write(_responseArray, 0, _responseArray.Length); // write bytes to the output stream
context.Response.KeepAlive = false; // set the KeepAlive bool to false
context.Response.Close(); // close the connection
Console.WriteLine("Respone given to a request.");
}
}