Search

Arduino1O1

Arduino, ESP8266 and Web Tricks

How to refresh the browser’s web page from Sublime Text?

If you are using the elegant Sublime Text editor to write your web pages, and you want to refresh the page using the keyboard. Here is the trick:

1/ Open Sublime Text and create a new file and save it to C:/refresh.vbs

2/ If you are using Google Chrome, paste these lines to the created file:

Set chrome = WScript.CreateObject(“WScript.Shell”)
chrome.AppActivate(“chrome”)
chrome.SendKeys “{F5}”
chrome.AppActivate(“TextPad”)

Or if you are using Mozilla Firefox then paste this instead:

Set firefox = WScript.CreateObject(“WScript.Shell”)
firefox.AppActivate(“firefox”)
firefox.SendKeys “{F5}”
firefox.AppActivate(“TextPad”)

Save the file and close it.

2 / Go to Tools -> Build System -> New Build System

01

3/ Change the content of the new build system file to:

{
“shell_cmd”: “C:/refresh.vbs”
}

Save the file as webpreview.sublime-build.

4/ Go to Tools -> Build System and make sure webpreview is checked.

Make sure your browser active tab is the one showing the page you’re creating, then you should be able to preview the page by pressing Ctrl+B .

Done, happy coding!

Featured post

Ping a host using ESP8266

ESP8266Ping is a handy library that you can use to ping remote hosts using the famous ESP8266. Download it.

Sample code:

/*
With this library an ESP8266 can ping a remote machine and know if it's reachable.
It provides some basic measurements on ping messages (avg response time).
*/

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

const char* ssid = "YOUR_SSID"; // Your Wifi Name
const char* password = "YOUR_PASSWORD"; // Wifi Password

const IPAddress remote_ip(8, 8, 8, 8); // Remote host

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network

Serial.println();
Serial.println("Connecting to WiFi");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}

Serial.println();
Serial.print("WiFi connected with ip ");
Serial.println(WiFi.localIP());

Serial.print("Pinging ip ");
Serial.println(remote_ip);

// Ping
if (Ping.ping(remote_ip)) {
Serial.println("Success!!");
} else {
Serial.println("Error :(");
}
}

void loop() {
// loop
}

How to use ESP8266 Promiscuous Mode?

The ESP8266 is an amazing cheap microcontroller that has WiFi capability embedded. One of its fun features is that you can use it in Promiscuous Mode to sniff packets.

Here is the Arduino code for ESP8266:

#ifdef ESP8266
extern "C" {
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_config.h"
#include "user_interface.h"
}
#endif

int ap_channel = 1; // AP channel
char ap_mac[6] = { 0x34, 0xCD, 0xBE, 0x56, 0x64, 0xA0 }; // AP MAC

struct RxControl {
signed rssi: 8;
unsigned rate: 4;
unsigned is_group: 1;
unsigned: 1;
unsigned sig_mode: 2;
unsigned legacy_length: 12;
unsigned damatch0: 1;
unsigned damatch1: 1;
unsigned bssidmatch0: 1;
unsigned bssidmatch1: 1;
unsigned MCS: 7;
unsigned CWB: 1;
unsigned HT_length: 16;
unsigned Smoothing: 1;
unsigned Not_Sounding: 1;
unsigned: 1;
unsigned Aggregation: 1;
unsigned STBC: 2;
unsigned FEC_CODING: 1;
unsigned SGI: 1;
unsigned rxend_state: 8;
unsigned ampdu_cnt: 8;
unsigned channel: 4;
unsigned: 12;
};

struct LenSeq {
uint16_t length;
uint16_t seq;
uint8_t address3[6];
};

struct sniffer_buf {
struct RxControl rx_ctrl;
uint8_t buf[36];
uint16_t cnt;
struct LenSeq lenseq[1];
};

struct sniffer_buf2 {
struct RxControl rx_ctrl;
uint8_t buf[112];
uint16_t cnt;
uint16_t len;
};
unsigned long time_ = 0;

// Callback function
void ICACHE_FLASH_ATTR promisc_cb(uint8 *buf, uint16 len) {
if (len == 12) {
struct RxControl *sniffer = (struct RxControl*) buf;
} else if (len == 128) {
struct sniffer_buf2 *sniffer = (struct sniffer_buf2*) buf;
int i = 0;
// Check MAC
for (i = 0; i < 6; i++) if (sniffer->buf[i + 10] != ap_mac[i]) return;
Serial.printf("RSSI: %2d (%d ms)\n", sniffer->rx_ctrl.rssi, millis() - time_);
time_ = millis();
} else {
struct sniffer_buf *sniffer = (struct sniffer_buf*) buf;
int i = 0;
// Check MAC
for (i = 0; i < 6; i++) if (sniffer->buf[i + 10] != ap_mac[i]) return;
Serial.printf("RSSI: %2d (%d ms)\n", sniffer->rx_ctrl.rssi, millis() - time_);
time_ = millis();
}
}

void setup() {
Serial.begin(115200);
Serial.println(" -> WiFi Sniffer");
Serial.println(" -> Initializing!\n\n");
wifi_set_opmode(0x1);
wifi_set_channel(ap_channel);
wifi_promiscuous_enable(0);
wifi_set_promiscuous_rx_cb(promisc_cb);
wifi_promiscuous_enable(1);
Serial.println(" -> Init finished!\n\n");
time_ = millis();
}

void loop(){
// Loop
}

Website Powered by WordPress.com.

Up ↑