Question about code on my ESP32 Arduino

speedi13578
Posts: 1
Joined: Thu Dec 07, 2017 2:31 pm

Question about code on my ESP32 Arduino

Postby speedi13578 » Thu Dec 07, 2017 2:35 pm

Hey guys im new to this whole community! First time setting something up like this. I have a problem with my code and can't seem to solve it. So i want to set up my arduino to show my the price of the bitcoin. Thanks so much for the help so far!!

The problem is that i am getting an error message, this one to be exact:


Arduino: 1.8.5 (Mac OS X), Board: "WEMOS LOLIN32, 80MHz, 921600"

fork/exec /Applications/Arduino.app/Contents/Java/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++: no such file or directory
Error compiling for board WEMOS LOLIN32.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

This is the original code for the Price of bitcoin!:



Code: Select all

#include <WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <Wire.h>
#include "SSD1306.h"
#include <WebServer.h>

// pins
#define SDA 5
#define SCL 4
#define I2C 0x3C

// create display
SSD1306 display(I2C, SDA, SCL);

// wifi settings
const char* host     = "api.coindesk.com";
const char* ssid     = "PUT YOUR SSID HERE";  // REPLACE THIS TO YOUR WIFI SETTINGS
const char* password = "PUT YOUR PASSWORD HERE";  // Ditto

//ESP8266WebServer server(80);
WebServer server ( 80 );
void handle_root() {
  server.send(200, "text/plain", "Hello from the esp32");
  delay(100);
}

void setup() {
  Serial.begin(115200);
  delay(100);

  display.init();
  display.flipScreenVertically();
  display.clear();
  display.display();

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handle_root);

  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient(); 

  display.clear();
  display.setFont(ArialMT_Plain_24);
  display.drawString(8, 20, "Updating ...");
  display.display();

  // Connect to API
  Serial.print("connecting to ");
  Serial.println(host);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  // We now create a URI for the request
  String url = "/v1/bpi/currentprice.json";

  Serial.print("Requesting URL: ");
  Serial.println(url);

  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(100);

  // Read all the lines of the reply from server and print them to Serial
  String answer;
  while(client.connected()){
    String line = client.readStringUntil('\r');
    answer += line;
  }

  client.stop();
  Serial.println();
  Serial.println("closing connection");

  // Process answer
  Serial.println();
  Serial.println("Answer: ");
  Serial.println(answer);

  // Convert to JSON
  String jsonAnswer;
  int jsonIndex;

  for (int i = 0; i < answer.length(); i++) {
    if (answer[i] == '{') {
      jsonIndex = i;
      break;
    }
  }

  // Get JSON data
  jsonAnswer = answer.substring(jsonIndex);
  Serial.println();
  Serial.println("JSON answer: ");
  Serial.println(jsonAnswer);
  jsonAnswer.trim();

  // Get rate as float
  int rateIndex = jsonAnswer.indexOf("rate_float");
  String priceString = jsonAnswer.substring(rateIndex + 12, rateIndex + 18);
  priceString.trim();
  float price = priceString.toFloat();

  // Print price
  Serial.println();
  Serial.println("Bitcoin price: ");
  Serial.println(price);

  // Display on OLED
  display.clear();
  display.setFont(ArialMT_Plain_16);
  display.drawString(32, 0, "BTC Price:");
  display.setFont(ArialMT_Plain_24);
  display.drawString(32, 20, priceString);
  display.drawString(6, 20, "$");
  display.setFont(ArialMT_Plain_16);
  display.drawString(32, 44, "Awh Yeah");
  display.display();

  // Wait 15 seconds
  delay(15000);
}

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 2 guests