A
A
Artyom Sedinin2022-04-16 22:35:02
Microcontrollers
Artyom Sedinin, 2022-04-16 22:35:02

How to connect android application written in Xamarin Forms and ESP8266?

I will describe as briefly as possible.
We have a project called the WindyBox, a conventional mobile, battery-powered smoke extractor that is needed to filter out harmful substances generated during soldering.
This device consists of a cooler and a case. This cooler will be regulated, as I understand it, by a transistor, but the transistor will be regulated by a PWM created by ESP8266.
There is an application, here it is , and I need to somehow link it to the ESP8266.
I have an ESP8266 like this. 625b15311bb30941755244.png
I don’t understand at all how to coordinate the work of the ESP8266 and the application.
Personally, I'm interested in how to program an application so that it can work in harmony with the ESP8266.
I have already dug something in the internet and realized that all this, apparently, should work in the server-client mode.
I have a code here that raises a lot of questions, it is from this site
, here it is.

using System.Net.Sockets;
using System;
namespace TCPIP
{
    internal class Program
    {
        static void Main(string[] args)
        {
            TcpListener ServerSocket = new TcpListener(8888);
            int requestCount = 0;
            TcpClient clientSocket = default(TcpClient);
            ServerSocket.Start();
            Console.WriteLine(">> Server Started");
            clientSocket = ServerSocket.AcceptTcpClient();
            Console.WriteLine(">> Accept connection from client");
            requestCount = 0;
            while (true)
            {
                try
                {
                    requestCount++;
                    NetworkStream networkStream = clientSocket.GetStream();
                    byte[] bytesFrom = new byte[10025];
                    networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                    string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
                    dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                    Console.WriteLine(">> Data fromClient - " + dataFromClient);
                    string serverResponce = "Last message from client " + dataFromClient;
                    Byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes(serverResponce);
                    networkStream.Write(sendBytes, 0, sendBytes.Length);
                    networkStream.Flush();
                    Console.WriteLine(">> " + serverResponce);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
        clientSocket.Close();//с этого участка кода всё красное.
        ServerSocket.Stop();
        Console.WriteLine(">> exit");
        Console.ReadLine();
    }
}

There, wavy red code appears below, and the development environment does not say that it is not reachable due to the loop from above, it writes that clientSocket does not exist in the current context, tokens, etc.
625b17e6c8eca987000516.png
How to fix it?
Can you please advise some normal sources on this topic of networks related to mobile C # applications in conjunction with the ESP8266. I don't know what to do anymore. I don't understand anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Антон Шаманов, 2022-04-16
@SilenceOfWinter

перед тем как браться за подвиги убедись что ты в сказке(с)
вначале выучи C#, а потом уже пытайся что-то на нем писать.
документация по железке тут
ESP8266 это микроконтроллер с wifi модулем, на нем можно поднять http "сервер" и обмениваться данными как с любым другим веб сервером. примеры реализации

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question