Transmit data over WiFi modem
ESP_8266.h@0:0b46638559b3, 2019-06-13 (annotated)
- Committer:
- docent
- Date:
- Thu Jun 13 13:49:26 2019 +0000
- Revision:
- 0:0b46638559b3
To my students 13.06.2019
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
docent | 0:0b46638559b3 | 1 | #ifndef ESP_8266_h |
docent | 0:0b46638559b3 | 2 | #define ESP_8266_h |
docent | 0:0b46638559b3 | 3 | #include "mbed.h" |
docent | 0:0b46638559b3 | 4 | |
docent | 0:0b46638559b3 | 5 | const uint16_t RXWIFI_BUFFER_SIZE = 256*5; |
docent | 0:0b46638559b3 | 6 | typedef struct { |
docent | 0:0b46638559b3 | 7 | char IPaddr[16]; |
docent | 0:0b46638559b3 | 8 | char UDPport[8]; |
docent | 0:0b46638559b3 | 9 | volatile uint16_t in; // Circular buffer pointers, volatile makes read-modify-write atomic |
docent | 0:0b46638559b3 | 10 | uint8_t event; |
docent | 0:0b46638559b3 | 11 | uint8_t app; |
docent | 0:0b46638559b3 | 12 | uint8_t answer; |
docent | 0:0b46638559b3 | 13 | uint8_t ipd; |
docent | 0:0b46638559b3 | 14 | uint8_t cipdinfo; |
docent | 0:0b46638559b3 | 15 | int len; |
docent | 0:0b46638559b3 | 16 | char buffer[RXWIFI_BUFFER_SIZE]; //1280 |
docent | 0:0b46638559b3 | 17 | } RxWiFi_t; |
docent | 0:0b46638559b3 | 18 | |
docent | 0:0b46638559b3 | 19 | void WriteWiFi(uint8_t *sbuf, int len); |
docent | 0:0b46638559b3 | 20 | void WiFiDataProcessing(); |
docent | 0:0b46638559b3 | 21 | void IniWiFi(Serial *pwifi,DigitalOut *pCH_PD,DigitalOut *pled);//IniWiFi(); |
docent | 0:0b46638559b3 | 22 | void SendResponseWiFi(); |
docent | 0:0b46638559b3 | 23 | |
docent | 0:0b46638559b3 | 24 | uint8_t wifi_executeCallback(char *buffer); |
docent | 0:0b46638559b3 | 25 | void pc_printfCallback(char *buffer); |
docent | 0:0b46638559b3 | 26 | void ResponseWiFiCallback(char *data,uint8_t answer); |
docent | 0:0b46638559b3 | 27 | |
docent | 0:0b46638559b3 | 28 | extern RxWiFi_t rx_wifi; |
docent | 0:0b46638559b3 | 29 | |
docent | 0:0b46638559b3 | 30 | /************************************************************************************************ |
docent | 0:0b46638559b3 | 31 | * EXAMPLE * |
docent | 0:0b46638559b3 | 32 | * !!!!!!!!!!!!!!!!!!! Befor connection with AP, set AT+CWMODE_DEF=1 !!!!!!!!!!!!!!!!!!!!!* |
docent | 0:0b46638559b3 | 33 | *************************************************************************************************/ |
docent | 0:0b46638559b3 | 34 | /* |
docent | 0:0b46638559b3 | 35 | #include "mbed.h" |
docent | 0:0b46638559b3 | 36 | |
docent | 0:0b46638559b3 | 37 | #include "ESP_8266.h" |
docent | 0:0b46638559b3 | 38 | const int buffer_size = 255; // might need to increase buffer size for high baud rates |
docent | 0:0b46638559b3 | 39 | |
docent | 0:0b46638559b3 | 40 | typedef struct { |
docent | 0:0b46638559b3 | 41 | volatile uint8_t in; // Circular buffer pointers, volatile makes read-modify-write atomic |
docent | 0:0b46638559b3 | 42 | uint8_t event; |
docent | 0:0b46638559b3 | 43 | uint8_t app; |
docent | 0:0b46638559b3 | 44 | uint8_t answer; |
docent | 0:0b46638559b3 | 45 | char buffer[buffer_size]; |
docent | 0:0b46638559b3 | 46 | } RxPc; |
docent | 0:0b46638559b3 | 47 | |
docent | 0:0b46638559b3 | 48 | //@************************************************************************ |
docent | 0:0b46638559b3 | 49 | //@* Interface * |
docent | 0:0b46638559b3 | 50 | //@************************************************************************ |
docent | 0:0b46638559b3 | 51 | Serial wifi_modem(PB_6,PB_7); |
docent | 0:0b46638559b3 | 52 | DigitalOut CH_PD(PA_8); |
docent | 0:0b46638559b3 | 53 | DigitalOut wifi_led(LED1); |
docent | 0:0b46638559b3 | 54 | |
docent | 0:0b46638559b3 | 55 | CH_PD=0; |
docent | 0:0b46638559b3 | 56 | IniWiFi(&wifi_modem,&CH_PD,&wifi_led); |
docent | 0:0b46638559b3 | 57 | |
docent | 0:0b46638559b3 | 58 | |
docent | 0:0b46638559b3 | 59 | //@************************************************************************ |
docent | 0:0b46638559b3 | 60 | //@* Global variables * |
docent | 0:0b46638559b3 | 61 | //@************************************************************************ |
docent | 0:0b46638559b3 | 62 | |
docent | 0:0b46638559b3 | 63 | RxWiFi_t rx_wifi; |
docent | 0:0b46638559b3 | 64 | |
docent | 0:0b46638559b3 | 65 | //@************************************************************************ |
docent | 0:0b46638559b3 | 66 | //@* functions * |
docent | 0:0b46638559b3 | 67 | //@************************************************************************ |
docent | 0:0b46638559b3 | 68 | void WriteWiFi(uint8_t *sbuf, int len); |
docent | 0:0b46638559b3 | 69 | void WiFiDataProcessing(); |
docent | 0:0b46638559b3 | 70 | void IniWiFi(Serial *pwifi,DigitalOut *pCH_PD,DigitalOut *pled);//IniWiFi(); |
docent | 0:0b46638559b3 | 71 | void SendResponseWiFi(); |
docent | 0:0b46638559b3 | 72 | |
docent | 0:0b46638559b3 | 73 | uint8_t wifi_executeCallback(char *buffer); |
docent | 0:0b46638559b3 | 74 | void pc_printfCallback(char *buffer); |
docent | 0:0b46638559b3 | 75 | void ResponseWiFiCallback(char *data,uint8_t answer); |
docent | 0:0b46638559b3 | 76 | |
docent | 0:0b46638559b3 | 77 | //@************************************************************************ |
docent | 0:0b46638559b3 | 78 | //@* main * |
docent | 0:0b46638559b3 | 79 | //@************************************************************************ |
docent | 0:0b46638559b3 | 80 | |
docent | 0:0b46638559b3 | 81 | while(1) { |
docent | 0:0b46638559b3 | 82 | ................... |
docent | 0:0b46638559b3 | 83 | WiFiDataProcessing(); |
docent | 0:0b46638559b3 | 84 | SendResponseWiFi(); |
docent | 0:0b46638559b3 | 85 | .................. |
docent | 0:0b46638559b3 | 86 | } |
docent | 0:0b46638559b3 | 87 | |
docent | 0:0b46638559b3 | 88 | //@*********************************************************************** |
docent | 0:0b46638559b3 | 89 | //@* CALLBACK * |
docent | 0:0b46638559b3 | 90 | //@*********************************************************************** |
docent | 0:0b46638559b3 | 91 | void pc_printfCallback(char *buffer) |
docent | 0:0b46638559b3 | 92 | { |
docent | 0:0b46638559b3 | 93 | pc.printf("%s",buffer); |
docent | 0:0b46638559b3 | 94 | } |
docent | 0:0b46638559b3 | 95 | |
docent | 0:0b46638559b3 | 96 | //-------------------------------------------------- |
docent | 0:0b46638559b3 | 97 | void ResponseWiFiCallback(char *data,uint8_t answer) |
docent | 0:0b46638559b3 | 98 | { |
docent | 0:0b46638559b3 | 99 | Response(answer,data); |
docent | 0:0b46638559b3 | 100 | //---------------------information feedback ----------------- |
docent | 0:0b46638559b3 | 101 | //if(data[0]=='0') |
docent | 0:0b46638559b3 | 102 | // rx_wifi.answer=0; |
docent | 0:0b46638559b3 | 103 | } |
docent | 0:0b46638559b3 | 104 | |
docent | 0:0b46638559b3 | 105 | //--------------------------------------- |
docent | 0:0b46638559b3 | 106 | uint8_t wifi_executeCallback(char *buffer) |
docent | 0:0b46638559b3 | 107 | { |
docent | 0:0b46638559b3 | 108 | WIFI_exist=1; |
docent | 0:0b46638559b3 | 109 | PC_exist=0; |
docent | 0:0b46638559b3 | 110 | return execute(buffer); |
docent | 0:0b46638559b3 | 111 | } |
docent | 0:0b46638559b3 | 112 | */ |
docent | 0:0b46638559b3 | 113 | |
docent | 0:0b46638559b3 | 114 | #endif |