Skip to content

Instantly share code, notes, and snippets.

@SaheblalBagwan
Last active June 12, 2019 13:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SaheblalBagwan/fb516db75e7bc98393ace45584cea9b3 to your computer and use it in GitHub Desktop.
Save SaheblalBagwan/fb516db75e7bc98393ace45584cea9b3 to your computer and use it in GitHub Desktop.
/*
* Tutorial : Hornbill Industrial Data logger (Temp and Current )
* Sensor: Max6675 Temp Sensor, non-invasive Current Sensor sensor
* Reference links:
https://exploreembedded.com/wiki/Hornbill_Industrial_Data_Logger
https://exploreembedded.com/wiki/Secure_IOT_with_AWS_and_Hornbill_ESP32
https://exploreembedded.com/wiki/AWS_IOT_with_Arduino_ESP32
* Library Links:
https://github.com/ExploreEmbedded/Hornbill-Examples/tree/master/arduino-esp32/AWS_IOT/examples
https://github.com/openenergymonitor/EmonLib
https://github.com/adafruit/MAX6675-library
*/
#include <AWS_IOT.h>
#include <WiFi.h>
#include <max6675.h>
#include <EmonLib.h>
/************************************************************************
AWS Configuration
/************************************************************************/
char WIFI_SSID[]="your Wifi SSID";
char WIFI_PASSWORD[]="Wifi Password";
char HOST_ADDRESS[]="AWS host address";
char CLIENT_ID[]= "client id";
char TOPIC_NAME[]= "your thing/topic name";
/***********************************************************************/
/**********************************************************
Pin Mapping
**********************************************************/
int thermoDO = 27;
int thermoCS = 14;
int thermoCLK = 12;
int currentPin = 36;
/*********************************************************/
/*********************************************************
Create instances
/*********************************************************/
AWS_IOT AWS_CLIENT;
MAX6675 thermoCouple(thermoCLK, thermoCS, thermoDO);
EnergyMonitor emon;
/*********************************************************/
int status = WL_IDLE_STATUS;
int tick=0, publishMsg=0;
char payload[512];
void setup() {
Serial.begin(115200);
delay(2000);
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(WIFI_SSID);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
// wait 5 seconds for connection:
delay(5000);
}
Serial.println("Connected to wifi");
if(AWS_CLIENT.connect(HOST_ADDRESS,CLIENT_ID)== 0)
{
Serial.println("Connected to AWS");
delay(1000);
}
else
{
Serial.println("AWS connection failed, Check the HOST Address");
while(1);
}
delay(2000);
emon.current(currentPin, 111.1); // Current: input pin, calibration.
}
void loop() {
double Irms,power,tempCelcius;
if(tick >= 5) // Publish every 5secs
{
tempCelcius = thermoCouple.readCelsius();
Irms = emon.calcIrms(1480); // Calculate Irms only
power = 230 * Irms;
sprintf(payload,"Temperature:%f'C, Irms Current:%fA, Power:%fW",tempCelcius,Irms,power);
if(AWS_CLIENT.publish(TOPIC_NAME,payload) == 0)
{
Serial.println(payload);
tick = 0; // Publish successfull, wait for 5more seconds
}
else
{
Serial.println("Publish failed, Will try again after 1sec");
}
}
else
{
tick++;
}
vTaskDelay(1000 / portTICK_RATE_MS);
}
@amrhzaa3
Copy link

how this code run in hornbill dev kit which has 12 bit ADC and the Emonlib use 10 bit adc by default ?

@ArnyminerZ
Copy link

how this code run in hornbill dev kit which has 12 bit ADC and the Emonlib use 10 bit adc by default ?

I was wondering exactly the same. I'm trying it next friday, has anyone tried it?

Planning to use it only with EmonLib and some LM35, any warnings to have in count??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment