I have two Adafruit HUZZAH ESP8266 Breakout boards, and I'm trying to send data between them and to a PC. What I currently have is one set as the "host" and the other at the "client". Both receive data in the same format via serial from two Teensy 4.1's, and the client ESP8266 sends the data over Wi-Fi to the host ESP8266, which then combines the data which is retrieved when a PC on the host Wi-Fi network sends a request.
The program on the host works fine, but the data it receives from the client is truncated, with some of the first half of the data missing.
Here's the section of the code from each Teensy 4.1 which sends the data to each ESP8266 via hardware serial 7 (all variables are floats, apart from shoe, which is a string of no more than 5 characters):
Code: Select all
String dataString = "";
dataString += shoe + ","+ String(myTime) + "," + String(T1)+ "," + String(T2)+ "," + String(T3)+ "," + String(T4) + "," + String(T5)+ "," + String(T6)+ "," + String(T7)+ "," + String(T8)+ "," + String(F1)+ "," + String(F2) + "," + String(F3)+ "," + String(F4)+ "," + String(F5)+ "," + String(F6)+ "," + String(F7)+ "," + String(F8) + "," + String(strainout[1])+ "," + String(strainout[2])+ "," + String(strainout[3])+ "," + String(strainout[4])+ "," + String(strainout[5]) + "," + String(strainout[6])+ "," + String(strainout[7])+ "," + String(strainout[8]) + "," + String(strainout[9]) + "," + String(state);
// WIFI print
Serial7.println(dataString);
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#ifndef APSSID
#define APSSID "HappierFeetWifi_Hub"
#endif
/* Set these to your desired credentials. */
const char *ssid = APSSID;
String hubdata;
String clientdata;
ESP8266WebServer server(80);
WiFiServer serialserver(160);
void handleData() {
server.send(200, "application/json", hubdata + clientdata);
delay(1);
}
void setup() {
delay(1000);
Serial.begin(921600);
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid);
IPAddress myIP = WiFi.softAPIP();
server.on("/data", handleData);
server.begin();
serialserver.begin();
}
void loop() {
//hubdata = "";
if ( Serial.available() ) {
hubdata = Serial.readStringUntil('\n');
}
WiFiClient client = serialserver.available();
if (client) {
while (client.connected()) {
if (client.available()) {
clientdata = client.readStringUntil('\n');
}
}
client.stop();
}
server.handleClient();
}
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <UrlEncode.h>
const char *hub_ssid = "HappierFeetWifi_Hub";
const char *ssid = "HappierFeetWifi_Client";
String data;
WiFiClient client;
void setup() {
delay(1000);
Serial.begin(921600);
WiFi.mode(WIFI_STA); //station mode
WiFi.begin(hub_ssid); //Connect to this SSID.
while (WiFi.status() != WL_CONNECTED) { //Wait for getting IP assigned by Access Point/ DHCP.
delay(500);
}
}
void loop() {
if ( Serial.available() ) {
data = Serial.readStringUntil('\n');
if (client.connect("192.168.4.1", 160)) {
client.println(data);
client.stop();
}
}
delay(10);
}