I am using React Native with socket.io to send data to Arduino using sockets. I'm just getting confused because my arduino prints this string as output (instead of "hello world")
GET /socket.io/?EIO=3&transport=polling&t=N3MDU9z HTTP/1.1
accept: */*
Host: 192.168.1.109
Connection: Keep-Alive
Accept-Encoding: gzip
User-Agent: okhttp/3.12.1
I have this code running on my ESP8266 to receive and print a string from the client
#include "ESP8266WiFi.h"
const char* ssid = "SSID";
const char* password = "PASSWORD";
WiFiServer wifiServer(80);
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
wifiServer.begin();
}
void loop() {
WiFiClient client = wifiServer.available();
if (client) {
while (client.connected()) {
while (client.available()>0) {
char c = client.read();
Serial.write(c);
}
delay(10);
}
client.stop();
Serial.println("Client disconnected");
}
}
and here is the code for the client (js)
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import io from 'socket.io-client';
export default class App extends React.Component{
constructor(props) {
super(props);
}
componentDidMount() {
const socket = io("http://192.168.1.109:80");
socket.emit("message","hello world");
}
render(){
return(
<View style={styles.container}>
<Text>Hello</Text>
</View>
)
}
}
Does anyone have any advice?