H.Ghorbanpanah
Published

Smart Microgrid Monitoring

Smart City is one of the big ideas. We need a lot of smart devices with different abilities for designing a smart city.

AdvancedShowcase (no instructions)1,156
Smart Microgrid Monitoring

Things used in this project

Hardware components

SUNNY WEBBOX
×1
MTA8000(EMS Panel)
×1

Software apps and online services

Arduino IDE
Arduino IDE
QT
Create connected devices, UIs and applications that run anywhere on any device, on any operating system at any time.

Story

Read more

Schematics

Schematic of data network

This project includes the following parameters:
1- LinkIt ONE (WiFi module)
2- Energy management module
3- Sunny WebBox (read data parameters of Inverters and micro grid status

Code

QT source code

C/C++
QT source code for control and monitoring application
No preview (download only).

Web Server for Monitoring micro-grid objects

Arduino
/*
  WiFi Web Server

 A simple web server that a repeated counter

 Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH accordingly.

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe
 modified 20 Aug 2014
 by MediaTek Inc.
 */
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiServer.h>
#include <LWiFiClient.h>
#include <LBattery.h>

//#define WIFI_AP "Pronet1"
//#define WIFI_PASSWORD "!23$56&89"
#define WIFI_AP "MTACO"
#define WIFI_PASSWORD "1234567890"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration

String inputString = "";         // a string to hold incoming data
char* myObject[10]; //Array list of microgrid objects
int objectsNo=0; //No. of objects
boolean stringComplete = false;  // whether the string is complete

LWiFiServer server(80);

void setup()
{
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  LWiFi.begin();
  // initialize serial:
  Serial1.begin(9600);
  Serial.begin(115200);
  delay(2000);
  // keep retrying until connected to AP
  Serial.println("Connecting to AP");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }

  printWifiStatus();

  Serial.println("Start Server");
  server.begin();
  Serial.println("Server Started");
}

int loopCount = 0;

void loop()
{
  // put your main code here, to run repeatedly:
  delay(500);
  loopCount++;
  LWiFiClient client = server.available();
  if(Serial1Packet())
  {
    ListObjectTransfer();
    }
  if (client)
  {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected())
    {
      if (client.available())
      {
        // we basically ignores client request, but wait for HTTP request end
        int c = client.read();
        Serial.print((char)c);

        if (c == '\n' && currentLineIsBlank)
        {
          Serial.println("send response");
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          client.println("<PPanel>");
          client.println(myObject[0]);// Online power of solar panel
          client.println("<PPanel/>");
          client.println("<TotalG>");
          client.println(myObject[1]);// Online Total power generation from solar panel
          client.println("<TotalG/>");
          client.println("<Motion>");
          client.println(myObject[2]);// Status of motion sensor
          client.println("<Motion/>");
          client.println("<Battery>");
          client.print(LBattery.level());
          client.println("<Battery/>");
          client.println("<Signal>");
          client.print(LWiFi.RSSI());//-10dBm = Max & -100dBm = Min
          client.println("<Signal/>");
          client.println("<br/>");
          client.println("</html>");
          client.println();
          break;
        }
        if (c == '\n')
        {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(500);

    // close the connection:
    Serial.println("close connection");
    client.stop();
    Serial.println("client disconnected");
  }
}

void serial1Event() {
  while (Serial1.available()) {
    // get the new byte:
    char inChar = (char)Serial1.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    // ':' char is equal to end packet of transfer from EMS module
    if (inputString.endsWith("</P>")) {
      stringComplete = true;
    }
  }
}

void ListObjectTransfer()
{
  //You can find object of transfer fron serial port and saved them at myObject string array
  }

bool Serial1Packet()
{
  serial1Event(); //call the function
  // print the string when a newline arrives:
  if (stringComplete) {
    //Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
    return 1;
  }
  else
  return 0;
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(LWiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = LWiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  Serial.print("subnet mask: ");
  Serial.println(LWiFi.subnetMask());

  Serial.print("gateway IP: ");
  Serial.println(LWiFi.gatewayIP());

  // print the received signal strength:
  long rssi = LWiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

WiFiWebServer2.rar

Arduino
No preview (download only).

Credits

H.Ghorbanpanah

H.Ghorbanpanah

1 project • 4 followers
Research and Development Supervisor at Mashhad Electric Energy Distribution Co. M.SC.Computer Software Engineering

Comments