求助:提示uint8_t*和char*的问题

完整如下

#include <ESP8266.h>

#define SSID        "111"
#define PASSWORD    "yds111000"
#define HOST_NAME   "192.168.137.1"
#define HOST_PORT   80

ESP8266 wifi(&Serial1);
int LED = 6;
const char *hello = "GET /get HTTP/1.0\r\nHost: 192.168.137.1:80\r\nConnection: close\r\n\r\n";// HTTP 璇锋眰鏍煎紡锛岃缁嗚鏌ョ湅HTTP鍗忚
void setup(void)
{
  // put your setup code here, to run once:
 pinMode(LED,OUTPUT);
  
  WifiInit(Serial1, 115200);
  Serial.begin(115200); 
 
  Serial.print(F("FW Version:"));
  Serial.println(wifi.getVersion().c_str());

  if (wifi.setOprToStationSoftAP()) { 
    Serial.print(F("to station + softap ok\r\n"));
  } else {
    Serial.print(F("to station + softap err\r\n"));
  }

  if (wifi.joinAP(SSID, PASSWORD)) {
    Serial.print(F("Join AP success\r\n"));

    Serial.print(F("IP:"));   
    Serial.println( wifi.getLocalIP().c_str());
  } else {
    Serial.print(F("Join AP failure\r\n"));
  }

  if (wifi.disableMUX()) {  
    Serial.print(F("single ok\r\n"));
  } else {
    Serial.print(F("single err\r\n"));
  }
}

void loop(void)
{
  // put your main code here, to run repeatedly:
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
    Serial.print(F("create tcp ok\r\n"));
  } else {
    Serial.print(F("create tcp err\r\n"));
  }
  
  wifi.send((const uint8_t *)hello, strlen(hello) * sizeof(char)); 
  Serial.print("发送:");
  Serial.print(hello);

  uint8_t buffer[512] = {0};
  uint32_t len = wifi.recv(buffer, sizeof(buffer), 20000);
//    Serial.print(F("Received:["));
//    for (uint32_t i = 0; i < len; i++) {
//      Serial.print((char)buffer[i]);
//    }
    char response = (char)buffer[len-3];
    Serial.print("服务器返回:");
    Serial.print(response);
    if(response == '0'){
      digitalWrite(LED,LOW);
    } else {
      digitalWrite(LED,HIGH);
  }

  delay(1000);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值