Goal: Send two integer values from Arduino Nano to internet via ESP8266 using Arduino IDE
I am new to embedded programing and currently working on a project which sends some integer value from Arduino analog pins to an online database (IP address, port) via esp8266.
At this moment I know how to individually send data from ESP8266 to an IP keeping ESP in client mode. But I don't know how to transfer data generated at Arduno Nano to ESP8266.
#include <ESP8266WiFi.h>
#include<Wire.h>
const char *ssid = "SSID";
const char *password = "asdfghjkl";
const char* host = "192.222.43.1";
int portNum = 986;
WiFiClient client;
WiFiServer server(portNum);
void setup() {
Serial.begin(115200);
Wire.begin();
delay(10);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("WIFI OK");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("Connected to Wifi");
}
String message="";
void loop() {
message = "12,13"; // Message to be sent to ESP8266
if(!client.connected())
{
client.connect(host,portNum);
}
if(message.length()>0)
{
Serial.println(message);
client.println(message);
message="";
}
I can understand I would have to connect the TX-RX pin of Arduino - ESP to pass the data. But for some reason I am not able to make it work.
I would really appreciate if someone can help me understand the process with a simple example.
Thanks.
PS: The reason I had to use Arduino is because the sensor I am using need 2 analog Pins and ESP just have 1.