首页/作品列表/遥控小车
主要内容
#include
#include
#include

#if defined(__AVR_ATmega1284P__) || defined (__AVR_ATmega644P__) || defined(__AVR_ATmega128RFA1__)
#define EspSerial Serial1
#define UARTSPEED 115200
#endif
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
#include
SoftwareSerial mySerial(2, 3);
#define EspSerial mySerial
#define UARTSPEED 9600
#endif
ESP8266 wifi(&EspSerial);

bool wifimCottonbegin(const char* ssid, const char* pass, const char* id, const char* token)
{
WifiInit(EspSerial, UARTSPEED);
Serial.print(F("Start Connection mCotton...Waiting for 5S..."));
while (!wifi.setOprToStation());
while (!wifi.joinAP(ssid, pass));
wifi.setWiFiconnected(true);
while (!wifi.mqttSetServer("mCotton.microduino.cn", (1883)));
while (!wifi.mqttConnect(id, id, token));
wifi.setMqttConnected(true);
while (!wifi.mqttSetDiveceIDToken(id, token));
char SUBSCRIBTOPICA[30] = "";
strcat(SUBSCRIBTOPICA, "ca/");
strcat(SUBSCRIBTOPICA, id);
while (!wifi.mqttSetSubscrib(SUBSCRIBTOPICA));
char SUBSCRIBTOPICP[30] = "";
strcat(SUBSCRIBTOPICP, "cp/");
strcat(SUBSCRIBTOPICP, id);
while (!wifi.mqttSetSubscrib(SUBSCRIBTOPICP));
return true;
}

String uploadData(char* _st, int _data)
{
String send_data = "";
send_data = "{\"";
send_data += _st;
send_data += "\":\"";
send_data += _data;
send_data += "\"}";
return send_data;
}

String uploadData(char* _st, char* _data)
{
String send_data = "";
send_data = "{\"";
send_data += _st;
send_data += "\":\"";
send_data += _data;
send_data += "\"}";
return send_data;
}

String solution(String _sta, char *c)
{
String data;
if (strstr(_sta.c_str(), c) == NULL)
return "";
else
{
if (_sta.startsWith("{") && _sta.endsWith("}"))
{
_sta = _sta.substring(1, _sta.length() - 1);
_sta.replace("\"", "");
uint8_t _length = _sta.length();
char buf[_length];
char c_all[30] = "";
char data1[] = ":%s";
strcat(c_all, c);
strcat(c_all, data1);
sscanf(_sta.c_str(), c_all, &buf);
data = String(buf);
}
if (data != NULL)
return data;
}
}

ColorLED strip_2 = ColorLED(16, 2);

String PassageReceive;


void setup()
{
strip_2.begin();

if(wifimCottonbegin("asdfgh" , "88888888" , "5c95c37e30a51f0016df8be0" , "USDSeN9nLbyL"))
{
strip_2.setPixelColor(0,0x15fd12);

strip_2.show();
strip_2.setPixelColor(0,0xa455b3);

strip_2.show();

}

}

void loop()
{
PassageReceive = wifi.getMqttJson();
if (PassageReceive != "")
{
PassageReceive.trim();

if (wifi.isMqttConnected())
{
if(((solution(PassageReceive, "show_S1")) == 0))
{
strip_2.setPixelColor(0,0x3bfd0f);

strip_2.show();

}
if(((solution(PassageReceive, "show_S1")) == 0))
{
strip_2.setPixelColor(0,0x39fd0d);

strip_2.show();

}
if(((solution(PassageReceive, "show_S1")) == 0))
{
strip_2.setPixelColor(0,0x12fd12);

strip_2.show();

}

}
}

}
代码展示
暂无数据!
附件下载
  • 资料展示
  • 小车.zip
0
大牛,别默默的看了,快登录帮我点评一下吧!

立即注册