Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ESP8266.h"
- #include <SoftwareSerial.h>
- #define SSID "********"
- #define PASSWORD "********"
- #define HOST_NAME "www.google.com"
- #define HOST_PORT (80)
- #define ESP8266_USE_SOFTWARE_SERIAL
- SoftwareSerial MySerial(3, 2); /* RX:D3, TX:D2 */
- ESP8266 wifi(MySerial);
- void setup(void){
- Serial.begin(9600);
- if (wifi.setOprToStationSoftAP()) {
- Serial.print("to station + softap ok\r\n");
- } else {
- Serial.print("to station + softap err\r\n");
- }
- if (wifi.joinAP(SSID, PASSWORD)) {
- Serial.print("Join AP success\r\n");
- Serial.print("IP:");
- Serial.println( wifi.getLocalIP().c_str());
- } else {
- Serial.print("Join AP failure\r\n");
- }
- if (wifi.disableMUX()) {
- Serial.print("single ok\r\n");
- } else {
- Serial.print("single err\r\n");
- }
- Serial.print("setup end\r\n");
- //fim void
- }
- void lool(void){
- uint8_t buffer[1024] = {0};
- if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
- Serial.print("create tcp ok\r\n");
- } else {
- Serial.print("create tcp err\r\n");
- }
- const char *hello = "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n";
- wifi.send((const uint8_t*)hello, strlen(hello));
- uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
- if (len > 0) {
- Serial.print("Received:[");
- for(uint32_t i = 0; i < len; i++) {
- Serial.print((char)buffer[i]);
- }
- Serial.print("]\r\n");
- }
- if (wifi.releaseTCP()) {
- Serial.print("release tcp ok\r\n");
- } else {
- Serial.print("release tcp err\r\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement