NAzT
1/21/2016 - 8:58 AM

eesp8266-ga-real-time-event-tracking.ino

eesp8266-ga-real-time-event-tracking.ino

// Copyright Nat Weerawan 2015-2016
// MIT License

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiConnector.h>

HTTPClient http;
WiFiConnector *wifi;

#define WIFI_SSID        ""
#define WIFI_PASSPHARSE  ""

uint8_t SMARTCONFIG_BUTTON_PIN = 0;
const String ua = "UA-??????-1";
#include "init_wifi.h"

void init_hardware()
{
  Serial.begin(115200);
  delay(100);
  Serial.flush();
}

void setup()
{
  init_hardware();
  wifi = init_wifi(WIFI_SSID, WIFI_PASSPHARSE, SMARTCONFIG_BUTTON_PIN);
  wifi->setLed(16);

  wifi->on_connected([&](const void* message)
  {
    String url = "http://www.google-analytics.com/collect?v=1&t=event&cid=hello";
    path += "&dh=www.cmmakerclub.com&ec=ESPresso%20Lite&ea=Motion%20Sensor";
    path += "&cm5=1&el=Move!&tid=" + ua;

    http.begin(url.c_str()); //HTTP
    ESP.deepSleep(999999 * 1000000);
  });
  
  wifi->connect();
}

void loop()
{
  wifi->loop();
}