我正在进行的项目是BURSTCOIN自动收录器,它从Poloniex获取信息 使用ESP8266我遇到的第一个问题是我使用的是http.getstring,并且要进入字符串并且不断重启设备。然后我决定使用缓冲区,现在我可以将所有信息打印到串口。现在我遇到的问题是我在所有的块中寻找信息BTC_BURST。我想知道如果我可以在收到它之后将它拆分,而不是将我的块拆分128或256字节。 这是我的代码。
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
//#include <ArduinoJson.h>
#define LCD_ROWS 2
#define LCD_COLS 16
LiquidCrystal_I2C lcd(0x3F, LCD_COLS, LCD_ROWS);
WiFiManager wifiManager;
char apname[] = "ssid";
//char appass[] = "pass";
void configModeCallback (WiFiManager *myWiFiManager) {
lcd.home();
lcd.clear();
lcd.print("Now Entering");
lcd.setCursor(0, 1);
lcd.print("Setup Mode");
delay(2000);
lcd.home();
lcd.clear();
lcd.print("Pls Conn To AP");
lcd.setCursor(0, 1);
lcd.print(apname);
}
void setup() {
Serial.begin(115200);
Serial.println();
lcd.begin(4,5);
lcd.backlight();
startup();
thankyou();
lcd.home();
lcd.clear();
lcd.print("Connecting");
lcd.setCursor(0, 1);
lcd.print("To Local WiFi");
wifiManager.setTimeout(180);
wifiManager.setAPCallback(configModeCallback);
wifiManager.autoConnect(apname);//no password
//wifiManager.autoConnect(apname,appass);//with password
lcd.clear();
lcd.print("Connected!");
delay(2000);
}
void resetesp(){
wifiManager.resetSettings();
}
void startup(){
lcd.clear();
lcd.home();
lcd.print("Ticker Test");
lcd.setCursor(0, 1);
lcd.print("By Draknoid");
delay(2000);
}
void thankyou(){
lcd.clear();
lcd.home();
lcd.print("Thank You!");
lcd.setCursor(0, 1);
lcd.print("Your Name Here");
delay(2000);
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("https://poloniex.com/public?command=returnTicker","83:7D:87:4B:80:8B:B9:26:33:C0:5A:DC:30:18:58:D9:69:14:D1:4F"); //Specify request destination
int httpCode = http.GET();//Send the request
if(httpCode == HTTP_CODE_OK){
int len = http.getSize();// get lenght of document (is -1 when Server sends no Content-Length header)
// create buffer for read
char jsonBuffer[128]; // verify this
// get tcp stream
WiFiClient * stream = http.getStreamPtr();
// read all data from server
while(http.connected() && (len > 0 || len == -1)) {
// get available data size
size_t size = stream->available();
if(size) {
// read up to 128 byte
int c = stream->readBytes(jsonBuffer, ((size > sizeof(jsonBuffer)) ? sizeof(jsonBuffer) : size));
// write it to Serial
Serial.println(jsonBuffer);
if(len > 0) {
len -= c;
}
}
}
}
}
delay(10000);
}