HomeAut
ESP8266.h
1 /*******************************************************************************
2  * Purpose:
3  ******************************************************************************/
4 
5 #ifndef ESP8266_H_
6 #define ESP8266_H_
7 
8 
9 /*------------------------------------------------------------------------------
10  * Includes
11  *----------------------------------------------------------------------------*/
12 #include "include.h"
13 
14 
15 /*------------------------------------------------------------------------------
16  * Macros & definitions
17  *----------------------------------------------------------------------------*/
18 
19 
20 
21 #define ESP8266_BUFFER_LENGTH ( 70 )
22 // for ESP8266 receive buffer length
23 
24 
25 #define ESP8266_SERVER_IP_ADDRESS_SHORT ( 10 )
26 
27 
28 #define ESP8266_HOMEAUTMESSAGE_RECEIVEMESSAGE_QUEUE_LENGTH ( 5 )
29 #define ESP8266_HOMEAUTMESSAGE_SENDMESSAGE_QUEUE_LENGTH ( 5 )
30 
31 
32 #define ESP8266_HOMEAUT_MESSAGECONTENT_LENGTH ( 40 )
33 // example: "|HomeAut|010|014|LOGIN__|NMEDIU00000000|"
34 #define ESP8266_HOMEAUTMESSAGE_ITEM_SIZE ( ESP8266_HOMEAUT_MESSAGECONTENT_LENGTH + 1 )
35 
36 #define ESP8266_HOMEAUT_MESSAGEHEADER_LENGTH ( 12 )
37 // "\r\n"
38 // "+IPD,0,20:"
39 
40 #define ESP8266_HOMEAUT_MESSAGEBOTTOM_LENGTH ( 6 )
41 // "\r\nOK\r\n"
42 
43 #define ESP8266_HOMEAUT_RECEIVING_MESSAGE_LENGTH ( ESP8266_HOMEAUT_MESSAGECONTENT_LENGTH + \
44  ESP8266_HOMEAUT_MESSAGEHEADER_LENGTH + ESP8266_HOMEAUT_MESSAGEBOTTOM_LENGTH )
45 
46 
47 #define ESP8266_HOMEAUTMESSAGE_RECEIVEDMESSAGE_NULLCHAR ( 52 )
48 #define ESP8266_HOMEAUTMESSAGE_RECEIVEDMESSAGE_START ( 12 )
49 
50 /*------------------------------------------------------------------------------
51  * Type definitions
52  *----------------------------------------------------------------------------*/
53 
54 typedef enum {
55  ESP8266_ConnectionStatus_Unknown = 0,
56  ESP8266_ConnectionStatus_OnConnecting,
57  ESP8266_ConnectionStatus_SuccessfulConnected,
58  ESP8266_ConnectionStatus_SuccessfulServerStarted,
59  ESP8266_ConnectionStatus_ClosedConnection,
60  ESP8266_ConnectionStatus_Error
61 
62 } ESP8266_ConnectionStatusType;
63 
64 
65 typedef enum {
66  ESP8266_TcpConnectionStatus_Unknown = 0,
67  ESP8266_TcpConnectionStatus_Connected,
68  ESP8266_TcpConnectionStatus_Error
69 
70 } ESP8266_TcpConnectionStatusType;
71 
72 
73 
74 /*------------------------------------------------------------------------------
75  * Global variables
76  *----------------------------------------------------------------------------*/
77 extern UART_HandleTypeDef Esp8266UartHandle;
78 extern volatile uint8_t ESP8266_Uart_ReceivedCharFlag;
79 
80 #ifdef CONFIG_USE_FREERTOS
81 extern xSemaphoreHandle ESP8266_USART_Rx_Semaphore;
82 extern xQueueHandle ESP8266_SendMessage_Queue;
83 extern xQueueHandle ESP8266_ReceivedMessage_Queue;
84 #endif
85 
86 
87 extern ESP8266_ConnectionStatusType ESP8266_ConnectionStatus;
88 extern ESP8266_TcpConnectionStatusType ESP8266_TcpConnectionStatus;
89 
90 extern char ESP8266_MyIpAddressString[4];
91 extern uint8_t ESP8266_MyIpAddressDecimal;
92 extern uint8_t ESP8266_DebugEnableFlag;
93 
94 extern uint8_t ESP8266_Receive_Mode_FixLength;
95 extern uint8_t ESP8266_ReceiveBuffer_Cnt;
96 extern char ESP8266_ReceiveBuffer[ESP8266_BUFFER_LENGTH];
97 
98 
99 /*------------------------------------------------------------------------------
100  * Local variables
101  *----------------------------------------------------------------------------*/
102 
103 
104 /*------------------------------------------------------------------------------
105  * Local function declarations
106  *----------------------------------------------------------------------------*/
107 
108 
109 /*------------------------------------------------------------------------------
110  * Global function declarations
111  *----------------------------------------------------------------------------*/
112 void ESP8266_Test ( void );
113 void ESP8266_SendString (char *aTxBuffer);
114 void ESP8266_ReceiveString (char *aRxBuffer, uint8_t length); //*waitedString
115 void ESP8266_BufferReset (char *Buffer, uint8_t length);
116 void ESP8266_Task ( void );
117 
118 
119 ReturnType ESP8266_Init ( void );
120 
121 ReturnType ESP8266_Config ( void );
122 ReturnType ESP8266_ConnectToWifiNetwork ( void );
123 
124 ReturnType ESP8266_StartServer ( void );
125 ReturnType ESP8266_FindServer ( void );
126 ReturnType ESP8266_ConnectToServer ( void );
127 
128 ReturnType ESP8266_SendTcpMessage ( char *message );
129 ReturnType ESP8266_SendMessageToQueue ( uint8_t *message );
130 
131 ReturnType ESP8266_ReceiveFixTcpMessage ( void );
132 
133 ReturnType ESP8266_WaitClientConnect( void);
134 
135 ReturnType ESP8266_CheckReceiveMessage ( void );
136 
137 
138 void ESP8266_WaitAnswer(void);
139 
140 
141 
142 #endif /* ESP8266_H_*/