Hi all,
First post on this forum, don't be too hard)
Having a problem where I send data (int hour) from my Wemos D1 mini esp,via Serial to my Arduino Uno,
no data gets read..
To clear things up, they are connected by Uno pin1 RX-> ESP pin1 TX and
Uno pin2 TX-> Esp pin2 RX, both set to 9600 baud rate. Both a share a common ground,
and both receive their appropriate power. I have used multiple example snippets from the internet but have not come to a working solution now. I read some people still haven't figured it out for this combination.
Both ino's also attached. The reason for 2 boards is a lack of GPIO pins, but won't use a MCP23016/14 or FCP8574. (for those who noticed, only my 4x4 keypad and Ledstrip work without their library as this is mandatory by my guidelines).
Any help with this would be greatly appreciated ![]()
Esp:
#include <ESP8266WebServer.h>
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiClientSecure.h>
#include <SoftwareSerial.h>
#include <DS3231.h>
#include <Wire.h>
#include <NTPClient.h>
SoftwareSerial ESPserial(9,10); //RX & TX
//absent rtc
DS3231 rtc;
//Btc Api
const char* host = "api.coindesk.com";Â Â
int noDec = 0;
//Network
const char* ssid  = "NoWifi4U_2.4Ghz";
const char* password = "ValentinB00";
WiFiUDP ntpUDP;
const long utcOffsetInSeconds = 0;
NTPClient timeClient(ntpUDP, "be.pool.ntp.org", utcOffsetInSeconds);
WiFiClientSecure client;
//webserver
ESP8266WebServer server(80);
void handle_root() {
 server.send(200, "text/plain", "Hello from the esp32");
 delay(100);
}
int btc;
void setup() {
 Serial.begin(9600);
 ESPserial.begin(9600);
 WiFi.begin(ssid, password);
 while ( WiFi.status() != WL_CONNECTED ) {
  delay ( 500 );
  Serial.print ( "." );
 }
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
 server.on("/", handle_root);
 server.begin();
 Serial.println("HTTP server started");
 timeClient.begin();
 Wire.begin();
}
void loop() {
 server.handleClient();Â
 bool h12, pm;
 int hour = timeClient.getHours() + 1; // Get the hour
 int minute = timeClient.getMinutes(); // Get the minute
 timeClient.update();
 String newhour;
 String newminute;
 if (hour < 9)
 {
  newhour = '0'+ String(hour);
  Serial.println(newhour);
 }
 else
 {Serial.println(hour);}
 if (minute < 9)
 {
  newminute = '0'+ String(minute);
  Serial.println(newminute);
 }
 else
 {Serial.println(minute);}
 //Serial.print("connecting to ");
 Serial.println(host);
 WiFiClient client;
 const int httpPort = 80;
 if (!client.connect(host, httpPort)) {
  Serial.println("connection failed");
  return;
 }
 String url = "/v1/bpi/currentprice/USD.json";
 //Serial.print("requesting URL: ");
 //Serial.println(url);
 client.print(String("GET ") + url + " HTTP/1.1\r\n" +
       "Host: " + host + "\r\n" +
       "Connection: close\r\n\r\n");
 //Serial.println("request sent");
 String answer;
 while (client.connected()) {
  String line = client.readStringUntil('\r');
  answer += line;
 }
 client.stop();
 String jsonAnswer;
 int jsonIndex;
 for (int i = 0; i < answer.length(); i++) {
  if (answer[i] == '{') {
   jsonIndex = i;
   break;
  }
 }
 jsonAnswer = answer.substring(jsonIndex);
 //Serial.println("JSON answer: ");
 //Serial.println(jsonAnswer);
 jsonAnswer.trim();
 int rateIndex = jsonAnswer.indexOf("rate_float");
 String priceString = jsonAnswer.substring(rateIndex + 12, rateIndex + 18);
 priceString.trim();
 float price = priceString.toFloat();
 Serial.println(priceString);
 char sendBTC[10];
 dtostrf(price, 4, 0, sendBTC);
 sprintf(sendBTC, "%d", (int)price);
 ESPserial.write(1);
 Serial.println();
 delay(10000);
}
