-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending Data to Google Sheets #14
Comments
Hi @Alaa-Aim, glad you like it :) In fact You can retrieve all the data from espem and with some scripting skills can convert it to any format you like. I have some plans to implement storing stats data from controller's RAM to SD-CARD but do not have time to work on it right now. Maybe a little bit later, keep in touch :) |
@vortigont , Many thanks for your reply and useful information, waiting for you new update on the ESPEM ...... |
@vortigont can I use the method used in this repository |
I never used google sheets API, sorry. You can try to send some data same way you've set voltage alerts, might work I suppose. |
I prefer local SQLite database storage for meter data, btw. A simple script running on raspberry store the data from espem int DB. |
@vortigont many thanks for your replies, I'll try Google Sheets First, then SQL, I'll let you know if I succeeded. |
@vortigont I used the code below and worked like charm , but when I combine it with your code, the code work but nothing uploaded to the GS. #include <PZEM004Tv30.h> #define PZEM_RX_PIN 16 const char * ssid = "XXX"; // type your Wifi name const int sendInterval = 50; void setup() { // Uncomment in order to reset the internal energy counter void loop() { // Read the data from the sensor write_google_sheet( "value1=" + String(Voltage) + "&value2=" + String(Current) + "&value3=" + String(Power) + "&value4=" + String(Energy) + "&value5=" + String(Frequency) + "&value6=" + String(Pf)); // Check if the data is valid
} if ((Voltage) >= 240.00) { String vString = String(Voltage);// using a , DEC for int, 3 for float, BIN for binary, HEX for Hexadecimal, none for display the value as is display.clearDisplay(); ALAA("Voltage: ", 2, 8, 1, false); ALAA("Current: ", 2, 28, 1, false); ALAA("Frequency: ", 2, 48, 1, false); display.display(); void write_google_sheet(String params) { String payload; void ALAA(String text, int x, int y, int size, boolean d) { display.setTextSize(size); } |
Well, can't tell you much without seeing the code. At least you should have some log data printer over serial I suppose |
@vortigont I cant compile and upload with debug on, as I've used all the pins, pin 1 & 3 used for the PZEM module, below is the code in main.cpp `/* ESPEM - ESP Energy monitor
*/ // Main headers #define SCREEN_WIDTH 128 // OLED display width, in pixels #include <HTTPClient.h> String GOOGLE_SCRIPT_ID = "AKfycby_n78L51euptIxZMd3cYTUp"; // Type your App Script id int ST1 = 17; // Relay 1 17 const long interval = 1000; // Timer Setting in lieu of delay const int numReadings = 50; // number of the array int analogInput = 34; #ifdef USE_FTP extern "C" int clock_gettime(clockid_t unused, struct timespec *tp); // PROGMEM strings // Our instance of espem // ---- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64) #ifdef ESPEM_DEBUG LOG(println, F("Starting EspEM...")); // Start framework, load config and connect WiFi // create and run ESPEM object if (espem && espem->begin(embui.paramVariant(FPSTR(V_UART)), embui.paramVariant(FPSTR(V_RX)), embui.paramVariant(FPSTR(V_TX))) ){ embui.server.on(PSTR("/fw"), HTTP_GET, [](AsyncWebServerRequest *request){ #ifdef USE_FTP //sync_parameters(); // sync UI params embui.setPubInterval(WEBUI_PUBLISH_INTERVAL); //run check every seconds pinMode(ST1, OUTPUT); digitalWrite(ST1, LOW); // MAIN loop mycheck(); embui.handle(); #ifdef USE_FTP unsigned long currentMillis = millis(); total = total - readings[readIndex]; // subtract the last reading: if ((unsigned long )(currentMillis - previousMillis) >= interval) { //checking the time elapsed
} } // send HTTP responce, json with controller/fw versions and status info timespec tp; request->send(200, FPSTR(PGmimejson), buff ); void ALAA(String text, int x, int y, int size, boolean d) { display.setTextSize(size); write_google_sheet( "value1=" + String(Voltaee) + "&value2=" + String(Current) + "&value3=" + String(Power) + "&value4=" + String(Energy) + "&value5=" + String(Frequncy) + "&value6=" + String(Pf)); if (m->voltage/10 > 210){ } String vString = String(m->voltage/10);// using a , DEC for int, 3 for float, BIN for binary, HEX for Hexadecimal, none for display the value as is display.clearDisplay(); ALAA("Voltage: ", 2, 8, 1, false); ALAA("Current: ", 2, 28, 1, false); ALAA("Frequency: ", 2, 48, 1, false); display.display(); } void write_google_sheet(String params) { String payload; void Check() if ( (average > 960) && (average < 1050) )
} if ( (average > 1051) && (average < 1130) )
} if ( (average > 1131) && (average < 1219) )
} if ( (average > 1220) && (average < 1326) )
} if ( (average > 1327) && (average < 1453) )
} if ( (average > 1454) && (average < 1614) )
} if ( (average > 1615) && (average < 1819) )
} if ( (average > 1820) && (average < 2079) )
} if ( (average > 2080) && (average < 2409) )
} if ( (average > 2410) && (average < 2854) )
} if ( (average > 2855) && (average < 3440) )
} if ( (average > 3441) && (average < 3900) )
} } |
You can use some pins temporary I suppose, just to fix the issue :)
This is wrong!
You should NOT put a call to mycheck(); into loop(){}, you make it running |
@vortigont , I did that, now it's working like a charm, data uploaded to GS and locally displayed on the WebUI, many tanks for your works and efforts. |
Cheers! |
@vortigont , I'm been using this project for a while, it's very nice built and the WebUI is good, I want to keep a log for all data been displayed on the WebUI by sending it to Google Sheet, is it possible to do that ?
The text was updated successfully, but these errors were encountered: