Patel Darshil
Published © GPL3+

Things You Should Know Before Using ESP8266 WiFi Module

Things you should know using ESP8266 WiFi module for its safety and easiness as it's very delicate module to use.

BeginnerProtip1 hour216,952
Things You Should Know Before Using ESP8266 WiFi Module

Things used in this project

Story

Read more

Code

Test Code

C/C++
// Include Libraries
#include "Arduino.h"
#include "ESP8266.h"
#include "dweet.h"


// Pin Definitions
#define ESP8266_PIN_RX	10
#define ESP8266_PIN_TX	11



// Global variables and defines

// ====================================================================
// vvvvvvvvvvvvvvvvvvvv ENTER YOUR WI-FI SETTINGS  vvvvvvvvvvvvvvvvvvvv
//
const char *SSID     = "WIFI-SSID"; // Enter your Wi-Fi name 
const char *PASSWORD = "PASSWORD" ; // Enter your Wi-Fi password
//
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ====================================================================


// These Dweet tokens have been auto generated for you.
char* const inputToken  = "59a7c547b7e19d001f7002d0_input";
char* const outputToken = "59a7c547b7e19d001f7002d0_output";

// object initialization
ESP8266 wifi(ESP8266_PIN_RX,ESP8266_PIN_TX);
Dweet dweet( &wifi, inputToken, outputToken);



// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time0;

// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity.
void setup() 
{
    // Setup Serial which is useful for debugging
    // Use the Serial Monitor to view printed messages
    Serial.begin(9600);
    while (!Serial) ; // wait for serial port to connect. Needed for native USB
    Serial.println("start");
    
    wifi.init(SSID, PASSWORD);
    menuOption = menu();
    
}

// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop.
void loop() 
{
    
    
    
    else if (menuOption == '1') {
    
    //SET DWEETS
    
    dweet.setDweet("DemoKey", "DemoValue"); // replace with your own (key, value) pairs to dweet your data
    dweet.sendDweetKeys();
    
    
    //GET DWEETS  
    dweet.receiveDweetEvents();
    
    if(!strcmp(dweet.getValue() , "DemoEventName"))
    {
        Serial.println("DemoEventName received!");
        // Do something
    }
    }
    
    if (millis() - time0 > timeout)
    {
        menuOption = menu();
    }
    
}



// Menu function for selecting the components to be tested
// Follow serial monitor for instrcutions
char menu()
{

    Serial.println(F("\nWhich component would you like to test?"));
    Serial.println(F("(1) IOT"));
    Serial.println(F("(menu) send anything else or press on board reset button\n"));
    while (!Serial.available());

    // Read data from serial monitor if received
    while (Serial.available()) 
    {
        char c = Serial.read();
        if (isAlphaNumeric(c)) 
        {
            
    		else if(c == '1') 
    			Serial.println(F("Now Testing IOT"));
            else
            {
                Serial.println(F("illegal input!"));
                return 0;
            }
            time0 = millis();
            return c;
            }
        }
    }

Credits

Patel Darshil

Patel Darshil

29 projects • 162 followers
I am an Electronics Hobbyist pursuing my BE in Electronics and communication

Comments