AlliedC
Published © GPL3+

IoT Data Logger

Want to optimize your power consumption? This IoT Data Logger is for you!

IntermediateWork in progress2,248
IoT Data Logger

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Code

Connectivity Code

C/C++
#include <EmonLib.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>  
#include <ThingSpeak.h> 

#define CURRENT_CAL 50.1

EnergyMonitor emon1;


const char ssid     = "your network SSID";
const char password = "password";

WiFiClient client;  
unsigned long myChannelNumber = channel no ;  
const char * myWriteAPIKey = "write api key"; 


int pin_Out_S0 = D6;
int pin_Out_S1 = D7;
int pin_Out_S2 = D8;
int pin_Out_CXT = D4;
int pin_In_Mux1 = A0;
float Mux1_State[8] = {0};
boolean DEBUG=true;


//======================================================================== setup
void setup()
{
  DEBUG=true;
  pinMode(pin_Out_S0, OUTPUT);
  pinMode(pin_Out_S1, OUTPUT);
  pinMode(pin_Out_S2, OUTPUT);
  pinMode(pin_Out_CXT, OUTPUT);
     digitalWrite(pin_Out_S0, HIGH );
     digitalWrite(pin_Out_S1, HIGH );
     digitalWrite(pin_Out_S2, HIGH );
  Serial.begin(9600);
  emon1.current(A0, CURRENT_CAL);

  Serial1.begin(115200);   // Your esp8266 module's speed is probably at 115200. 

 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(pin_Out_CXT, HIGH );
    delay(500);   
    digitalWrite(pin_Out_CXT, LOW );
    Serial.print(".");
  }

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

}
//======================================================================== loop
void loop()
{
  
  if (DEBUG)  Serial.println("Current="+String(Mux1_State[5])+" A");
  if (DEBUG)  Serial.println("Current="+String(Mux1_State[6])+" A");

  
  
   ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);   
  Serial.print("Current: ");
  Serial.println(currentDraw);
  Serial.println("\n\n");
 
 

 
  
  delay(12000);
}


}

Credits

AlliedC

AlliedC

1 project • 1 follower
Technology experts in IoT, Business Intelligence & EAI Services.

Comments