Rei Vilo
Published © CC BY-NC-SA

Private IoT with Blynk on Local Server

Concerned about IoT privacy on the cloud? Blynk offers an interesting option for improved security with a local server.

AdvancedFull instructions provided21,515
Private IoT with Blynk on Local Server

Things used in this project

Story

Read more

Code

blynkweather.ino

C/C++
///
/// @mainpage	blynkWeather
///
/// @details	Blynk with Weather for CC3200
/// @n
/// @n
/// @n @a		Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author		Rei Vilo
/// @author		http://embeddedcomputing.weebly.com
/// @date		23/07/2015 13:58
/// @version	101
///
/// @copyright	(c) Rei Vilo, 2015
/// @copyright	CC = BY SA NC
///
/// @see		ReadMe.txt for references
///


///
/// @file		blynkWeather.ino
/// @brief		Main sketch
///
/// @details	Example sketch
/// @n @a		Developed with [embedXcode+](http://embedXcode.weebly.com)
///
/// @author		Rei Vilo
/// @author		http://embeddedcomputing.weebly.com
/// @date		23/07/2015 13:58
/// @version	101
///
/// @copyright	(c) Rei Vilo, 2015
/// @copyright	CC = BY SA NC
///
/// @see		ReadMe.txt for references
/// @n
///


// Core library for code-sense - IDE-based
#if defined(ENERGIA) // LaunchPad specific
#include "Energia.h"
#else // error
#error Platform not defined
#endif // end IDE

// Include application, user and local libraries
#include "Wire.h"
#include "Sensor_BMP180.h"
#include "Sensor_DHT.h"
#include "Sensor_PIR.h"

#ifndef __CC3200R1M1RGC__ // Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include "WiFi.h"
#include <WiFiClient.h>
#include <BlynkSimpleCC3200.h>
#include "SimpleTimer.h"


// Prototypes


// Define variables and constants
Sensor_BMP180 myBMP180;
Sensor_DHT myDHT(24, DHT22);
Sensor_PIR myPIR(27);


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "AuthToken";
SimpleTimer Timer;
const uint8_t myRelay = 23;

bool alarm = false;

void sendUptime()
{
    myPIR.get();
    alarm |= myPIR.status();
    BLYNK_LOG("myPIR    %8i %8i", myPIR.status(), alarm);
    digitalWrite(RED_LED, alarm);

    // You can send any value at any time.
    // Please don't send more that 10 values per second.
    Blynk.virtualWrite(4, alarm);
}

// Add setup code
void setup()
{
    Serial.begin(9600);

    Wire.begin(); // required by BMP180
    myBMP180.begin(3);
    myDHT.begin();
    myPIR.begin();
    
    pinMode(RED_LED, OUTPUT);
    digitalWrite(RED_LED, HIGH);
    delay(1000);
    digitalWrite(RED_LED, LOW);

    Blynk.begin(auth, "SSID", "password", 0); // WLAN_SEC_WPA2

    // Setup a function to be called every second
    Timer.setInterval(1000L, sendUptime);
}

// Add loop code
void loop()
{
    Blynk.run();
    Timer.run();
}

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (0)
BLYNK_READ(0)
{
    myBMP180.get();
    float t1 = myBMP180.temperature();
    float p  = myBMP180.pressure();
    // This command writes t1 to Virtual Pin (0)
    Blynk.virtualWrite(0, t1);
    // This command writes p to Virtual Pin (0)
    Blynk.virtualWrite(1, p);
    BLYNK_LOG("myBMP180 %8.1f %8.1f", t1, p);
}

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (2)
BLYNK_READ(2)
{
    myDHT.get();
    float t2 = myDHT.temperature();
    float rh = myDHT.humidity();
    // This command writes t2 to Virtual Pin (2)
    Blynk.virtualWrite(2, t2);
    // This command writes rh to Virtual Pin (3)
    Blynk.virtualWrite(3, rh);
    BLYNK_LOG("myDHT    %8.1f %8.1f", t2, rh);
}

// This function will be called every time
// when App writes value to Virtual Pin 5
BLYNK_WRITE(5)
{
    BLYNK_LOG("Reset alarm %s", param.asStr());
    // You can also use: asInt() and asDouble()
    if (param.asInt() > 0) alarm = false; // reset
}

Github

https://github.com/blynkkk/blynk-server#quick-local-server-setup-on-raspberry-pi

Credits

Rei Vilo

Rei Vilo

14 projects • 25 followers

Comments