This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
90 lines (73 loc) · 2.1 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/** ESP 8266 WLAN Modem initialisieren
* - muss als erstes erfolgen, damit die Verbindung zum AP steht
* - wenn das Modem nicht sauber oder zu langsam funktoniert, wait Zeiten erhoehen
*/
#include "mbed.h"
RawSerial pc( USBTX, USBRX );
RawSerial dev( PTC15, PTC14 );
// Reset Modem
DigitalOut rst( PTA19 );
DigitalOut led1( D11 );
DigitalOut led4( D12 );
/** Lesen von Modem, Ausgabe auf UART USB */
void recv()
{
led1 = !led1;
while( dev.readable() )
pc.putc( dev.getc() );
}
/** Schreiben auf Modem ab UART USB */
void send()
{
led4 = !led4;
while( pc.readable() )
dev.putc( pc.getc() );
}
/** Senden eines Strings an das Modem */
void send( char* out )
{
while ( *out != '\0' )
{
dev.putc( *out );
out++;
}
dev.putc( '\r' );
dev.putc( '\n' );
}
int main()
{
rst = 0;
// 1. Teil: Initialisierung - Baudraten muessen identisch sein
pc.baud( 115200 );
dev.baud( 115200 );
wait( 1.0f );
rst = 1;
pc.attach( &send, Serial::RxIrq );
dev.attach( &recv, Serial::RxIrq );
send( "AT+RST" ); // RESET Modem
wait( 2.0f );
send( "AT+GMR" ); // Ausgabe Firmware Version - optional
wait( 2.0f );
send( "AT+CWMODE=1" ); // Station Mode, d.h. Modem = Client zu AP
wait( 1.0f );
//send( "AT+CWLAP" ); // List AP - optional
//wait( 10.0f );
send( "AT+CWJAP=\"LERNKUBE\",\"l3rnk4b3\"" ); // Verbindung AP (SSID, PW)
wait( 10.0f );
send( "AT+CIFSR" ); // Ausgabe IP-Adresse
wait( 1.0f );
// 2. Teil: Webseite von google.com holen
send( "AT+CIPMUX=1" ); // Mehrere Verbindungen aktivieren
wait( 1.0f );
send( "AT+CIPSTART=4,\"TCP\",\"httpbin.org\",80" ); // Socket zu google.com oeffnen
wait( 1.0f );
send( "AT+CIPSEND=4,18" ); // 18 Zeichen senden
wait( 1.0f );
send( "GET / HTTP/1.0\r\n" ); // HTTP GET
wait( 2.0f );
// Passthrough USB - Modem (alle Befehle von Terminal 1:1 an Modem leiten und umgekehrt)
while(1)
{
sleep();
}
}