Skip to content

Instantly share code, notes, and snippets.

@robertely
Created August 22, 2018 04:26
Show Gist options
  • Save robertely/0cc2a863f59232f140beda4fa0c9ec43 to your computer and use it in GitHub Desktop.
Save robertely/0cc2a863f59232f140beda4fa0c9ec43 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
extern "C" {
#include "user_interface.h"
}
#define BME_SCK 5
#define BME_MISO 2
#define BME_MOSI 4
#define BME_CS 0
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
String alfa = "1234567890";
byte channel = 6;
uint8_t beacon_interval = 10;
// Beacon Packet buffer
uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, /* Frame Control*/
/*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* Duration */
/*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, /* DA */
/*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
/*22*/ 0xc0, 0x6c,
/*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00,
/*32*/ 0x64, 0x00,
/*34*/ 0x01, 0x04,
/* SSID */
/*36*/ 0x00, 0x06, 0x72, 0x72, 0x72, 0x72, 0x72, 0x72,
0x01, 0x08, 0x82, 0x84,
0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01,
/*56*/ 0x04};
void setup() {
delay(500);
wifi_set_opmode(STATION_MODE);
wifi_promiscuous_enable(1);
wifi_set_channel(channel);
// Randomize SRC MAC
packet[10] = packet[16] = 0xBE;
packet[11] = packet[17] = 0xEF;
packet[12] = packet[18] = 0x00;
packet[13] = packet[19] = random(256);
packet[14] = packet[20] = random(256);
packet[15] = packet[21] = random(256);
Serial.begin(115200);
Serial.println("BME280 test");
Serial.println();
bool status;
// default settings
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
}
void loop() {
String TEMP_F = String((int)(bme.readTemperature() * 1.8 + 32));
// Serial.print("Temperature = ");
// Serial.print(TEMP_F);
// Serial.println("*F");
// Randomize SSID (Fixed size 6. Lazy right?)
packet[38] = '!';
packet[39] = ' ';
packet[40] = TEMP_F[0];
packet[41] = TEMP_F[1];
packet[42] = '*';
packet[43] = 'F';
packet[56] = channel;
wifi_send_pkt_freedom(packet, 57, 0);
wifi_send_pkt_freedom(packet, 57, 0);
wifi_send_pkt_freedom(packet, 57, 0);
delay(beacon_interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment