Demo Program for FTKL-Tagung in November 2016 for HTTP MQTT Requests over ESP
Demo Programm der FTKL-Tagung für die IoT-Kommunikation über die Serielle Schnittstelle mit dem ESP8266-01 und in weiterer Folge Browser-/App-basierende Kommunikation bzw. mittels MQTT.
Anschluss des M0/M3-Boards - M3-ESP-Abbildung:
- VCC und CH_PD -> VOUT (3,3V) Pin 40
- GND -> GND Pin 1
- RX -> TX Pin 9
- TX -> RX Pin10
main.cpp@0:539ad965ba5c, 2016-11-06 (annotated)
- Committer:
- ftkl_user
- Date:
- Sun Nov 06 15:55:20 2016 +0000
- Revision:
- 0:539ad965ba5c
Demo Program for FTKL-Tagung in November 2016 for HTTP MQTT Requests over ESP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ftkl_user | 0:539ad965ba5c | 1 | #include <mbed.h> |
ftkl_user | 0:539ad965ba5c | 2 | //#include <config.h> // Bertl |
ftkl_user | 0:539ad965ba5c | 3 | #include <LM75B.h> |
ftkl_user | 0:539ad965ba5c | 4 | |
ftkl_user | 0:539ad965ba5c | 5 | DigitalOut LedD1(LED1); |
ftkl_user | 0:539ad965ba5c | 6 | DigitalOut LedD2(LED2); |
ftkl_user | 0:539ad965ba5c | 7 | DigitalOut LedD3(LED3); |
ftkl_user | 0:539ad965ba5c | 8 | DigitalOut LedD4(LED4); |
ftkl_user | 0:539ad965ba5c | 9 | |
ftkl_user | 0:539ad965ba5c | 10 | //Serial wifi(P1_0, P0_20); // Bertl |
ftkl_user | 0:539ad965ba5c | 11 | Serial wifi(p9, p10); // M0 |
ftkl_user | 0:539ad965ba5c | 12 | Serial pc(USBTX, USBRX); |
ftkl_user | 0:539ad965ba5c | 13 | LM75B sensor(p28, p27); |
ftkl_user | 0:539ad965ba5c | 14 | |
ftkl_user | 0:539ad965ba5c | 15 | char str[30]; |
ftkl_user | 0:539ad965ba5c | 16 | |
ftkl_user | 0:539ad965ba5c | 17 | int main() |
ftkl_user | 0:539ad965ba5c | 18 | { |
ftkl_user | 0:539ad965ba5c | 19 | wifi.printf("Hello M3 MQTT\n"); |
ftkl_user | 0:539ad965ba5c | 20 | |
ftkl_user | 0:539ad965ba5c | 21 | while (1) { |
ftkl_user | 0:539ad965ba5c | 22 | wifi.scanf("%s", str); |
ftkl_user | 0:539ad965ba5c | 23 | //wifi.printf("str: %s\n", str); |
ftkl_user | 0:539ad965ba5c | 24 | if(str[0] == 'H' && str[1] == 'L') // 1. GET--> Serving Requests part in http-server |
ftkl_user | 0:539ad965ba5c | 25 | wifi.printf( "HL Msg: %s\n", str); |
ftkl_user | 0:539ad965ba5c | 26 | if(str[0] == 'M' && str[1] == 'V') // 1. GET--> Serving Requests part in http-server |
ftkl_user | 0:539ad965ba5c | 27 | ;//Move(); // ?reqest=MV |
ftkl_user | 0:539ad965ba5c | 28 | else if(str[0] == 'T') { |
ftkl_user | 0:539ad965ba5c | 29 | if (str[1] == 'L') |
ftkl_user | 0:539ad965ba5c | 30 | ;//TurnLeft(); |
ftkl_user | 0:539ad965ba5c | 31 | else if (str[1] == 'R') |
ftkl_user | 0:539ad965ba5c | 32 | ;//TurnRight(); |
ftkl_user | 0:539ad965ba5c | 33 | } else { // 3. GET--> Serving M0 Board part in http-server |
ftkl_user | 0:539ad965ba5c | 34 | if(str[7] == '1') { // ?M0=SD&chan=04&state=1 --> M0_SD_04_1 |
ftkl_user | 0:539ad965ba5c | 35 | LedD1 = (str[9] -'0'); |
ftkl_user | 0:539ad965ba5c | 36 | wifi.printf( "LedD1\n"); |
ftkl_user | 0:539ad965ba5c | 37 | } |
ftkl_user | 0:539ad965ba5c | 38 | if(str[7] == '2') |
ftkl_user | 0:539ad965ba5c | 39 | LedD2 = (str[9] -'0'); |
ftkl_user | 0:539ad965ba5c | 40 | if(str[7] == '3') |
ftkl_user | 0:539ad965ba5c | 41 | LedD3 = (str[9] -'0'); |
ftkl_user | 0:539ad965ba5c | 42 | if(str[7] == '4') |
ftkl_user | 0:539ad965ba5c | 43 | LedD4 = (str[9] -'0'); |
ftkl_user | 0:539ad965ba5c | 44 | if(str[3] == 'G') |
ftkl_user | 0:539ad965ba5c | 45 | wifi.printf( "Temp: %f\n", sensor.read()); |
ftkl_user | 0:539ad965ba5c | 46 | } |
ftkl_user | 0:539ad965ba5c | 47 | } // 2. GET-->Serving Web Pages for config and reset |
ftkl_user | 0:539ad965ba5c | 48 | } |