Hello RTW Example

Simple application for sending "Hello" every 10 seconds through the Real Time Web.

Source Code:

/* * Created on: 20.06.2017 By Nornir * * RTW_Hello for the ESP8266 * * Simple application for sending "Hello" every 10 seconds through the real-time web. * * Paste this in a terminal window on your computer, to listen for data: * curl -k http://testing5.rtw.no/Hello -H "Synx-Cat: 4" -d "objectID=1&username=*****&password=*****" * * cURL for Windows: http://www.confusedbycode.com/curl/ * * To add ESP8266 libraries, add the URL to "Additional Boards Managers URL": * http://arduino.esp8266.com/stable/package_esp8266com_index.json * And intall the "esp8266" in Board Mannager. */

#include <Arduino.h> #include <Nornir_ESP8266.h>

// RTW SPESIFIC------------------------------------------------------------------------------------ // "http://yourdomain.com/service" const String host = "http://testing5.rtw.no/Hello"; const String data = "objectID=1&data=Hello"; // RTW SPESIFIC------------------------------------------------------------------------------------

// Prototype (From Library) int RTW_send_data(String host, String data);

void setup() { // Default baudrate for ESP8266 is 115200 Serial.begin(115200);

// Initialize the Digital pin 8 as Sink for LED, Open Drain // LED: 3v3(+) -> D8(-) pinMode(D8, OUTPUT); digitalWrite(D8, HIGH);

// SSID and password for your WIFI Router ("SSID", "password"); WiFi.begin("SSID", "Password"); }

void loop() { // Check WiFi Connection if (WiFi.status() == WL_CONNECTED) { RTW_send_data(host, data); // Flash LED digitalWrite(D8, LOW); delay(100); digitalWrite(D8, HIGH); delay(100); digitalWrite(D8, LOW); delay(100); digitalWrite(D8, HIGH); delay(100); delay(9600); } else { Serial.println("Error: WiFi not connected!"); delay(1000); } }

void RTW_send_data(String host, String data) { // Create Object and Begin Session HTTPClient http; http.begin(host); Serial.print("[HTTP] Started\n");

// Add Headers http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // RTW SPESIFIC------------------------------------------------------------------------------------ http.addHeader("Synx-Cat", "1"); // Synx Category 1, Send Data // RTW SPESIFIC------------------------------------------------------------------------------------

// Post HTTP, http_codes are found in ESP8266HTTPClient.h int http_code = http.POST(data);

if (http_code == HTTP_CODE_OK) { Serial.println("[HTTP] POST: Sucess"); } else { Serial.printf("[HTTP] POST: Error %d\n", http_code); } // End HTTP Session http.end(); Serial.print("[HTTP] Connection Closed\n"); }

Featured Tutorials
Recent Tutorials
Archive

Search By Tags

Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

hello@nornir.io

Tel: +47 482 01 265

Visiting: Christian Krogs gate 1,

0186 OSLO, NORWAY

  • LinkedIn Social Icon
  • Facebook Social Icon
  • YouTube Social  Icon