/*
 Large publish message MQTT example

  - connects to an MQTT server
  - publishes a large string of text to the topic "outTopic"
*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

const char *ssid =  "SDNet";   // cannot be longer than 32 characters!
const char *pass =  "CapstoneProject";   //

// Update these with values suitable for your network.
IPAddress server(192, 168, 1, 110);

WiFiClient wclient;
PubSubClient client(wclient, server);

void setup() {
  // Setup console
  Serial.begin(115200);
  delay(10);
  Serial.println();
  Serial.println();
}

void payload(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println("...");
    WiFi.begin(ssid, pass);

    if (WiFi.waitForConnectResult() != WL_CONNECTED)
      return;
    Serial.println("WiFi connected");
  }

  if (WiFi.status() == WL_CONNECTED) {
    if (!client.connected()) {
      if (client.connect("arduinoClient")) {
  client.publish("outTopic", write_payload, 65536);
      }
    }

    if (client.connected())
      client.loop();
  }
}


