I'm hoping to create a small unit powered by a LiPo battery (3.7v via a TP4056 charger) and has an SSD1306 Oled, I was wondering if I could edit this code (See below) to work with my mining pool cause it has an API key thing. do I have to edit the code entirely or just tweak it? I am fairly new to the Arduino scene so I don't quite understand all the programming as of yet.
########## (The Code) #################
#include <SoftwareSerial.h>
#include <JsonParser.h>
using namespace ArduinoJson::Parser;
#define SSID "" // insert your Wifi's SSID
#define PASS "" // insert your Wifi's password
#define DST_IP "188.226.224.148" //api.openweathermap.org 's IP Address
#define LOCATIONID "2925533" // Weather City ID
SoftwareSerial dbgSerial(2, 3); // RX, TX for debugging
JsonParser<32> parser;
void setup()
{
Serial.begin(9600); // for module
Serial.setTimeout(5000);
dbgSerial.begin(9600); // for debuging
dbgSerial.println("Init");
Serial.println("AT+RST"); // restet and test if module is redy
delay(1000);
if(Serial.find("ready")) {
dbgSerial.println("WiFi - Module is ready");
}else{
dbgSerial.println("Module didnt respond. Please reset.");
while(1);
}
delay(1000);
// try to connect to wifi
boolean connected=false;
for(int i=0;i<5;i++){
if(connectWiFi()){
connected = true;
dbgSerial.println("Connected to WiFi...");
break;
}
}
if (!connected){
dbgSerial.println("Coudn't connect to WiFi.");
while(1);
}
delay(5000);
Serial.println("AT+CIPMUX=0"); // set to single connection mode
}
void loop()
{
String cmd = "AT+CIPSTART="TCP","";
cmd += DST_IP;
cmd += "",80";
Serial.println(cmd);
dbgSerial.println(cmd);
if(Serial.find("Error")) return;
cmd = "GET /data/2.5/weather?id=";
cmd += LOCATIONID;
cmd += " HTTP/1.0\r\nHost: api.openweathermap.org\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(cmd.length());
if(Serial.find(">")){
dbgSerial.print(">");
}else{
Serial.println("AT+CIPCLOSE");
dbgSerial.println("connection timeout");
delay(1000);
return;
}
Serial.print(cmd);
unsigned int i = 0; //timeout counter
int n = 1; // char counter
char json[100]="{";
while (!Serial.find(""main":{")){} // find the part we are interested in.
while (i<60000) {
if(Serial.available()) {
char c = Serial.read();
json[n]=c;
if(c=='}') break;
n++;
i=0;
}
i++;
}
dbgSerial.println(json);
JsonObject root = parser.parse(json);
double temp = root["temp"];
double pressure = root["pressure"];
double humidity = root["humidity"];
temp -= 273.15; // from kelvin to degree celsius
dbgSerial.println(temp);
dbgSerial.println(pressure);
dbgSerial.println(humidity);
dbgSerial.println("====");
delay(600000);
}
boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");
String cmd="AT+CWJAP="";
cmd+=SSID;
cmd+="","";
cmd+=PASS;
cmd+=""";
dbgSerial.println(cmd);
Serial.println(cmd);
delay(2000);
if(Serial.find("OK")){
dbgSerial.println("OK, Connected to WiFi.");
return true;
}else{
dbgSerial.println("Can not connect to the WiFi.");
return false;
}
}
########## (End Of The Code) #################