ESP8266-01 поключить к передатчику XD-FST 433Mhz

Нет ответов
mihaser
Offline
Зарегистрирован: 05.03.2016

Здравствуйте!

Собственно инересует к модулю ESP8266-01 подключить передатчик 433Mhz

Для чего:

Нужно крутить камеру по радиоканалу 433 но из WEB интерфейса. Типа 4 ссылки ЛЕВЕЕ , ПРАВЕЕ . При нажатии на ссылку, отпавлять по радио 433 команды соответственно "1" или "2".

 

Раньше делал на другом стариньком модуле MRF24WB0MA. Были постоянные обрывы WiFi. Сейчас хочу упростить до ESP.

Вот код на старинькой плате:

 

#include <VirtualWire.h>
 
const int transmit_pin = 5;
int p = 0;
int led_pin = A0;
int but1 = 7;
int but2 = 6;
int wlan_but = 4;
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
 
// Wireless configuration parameters ----------------------------------------
 
unsigned char local_ip[] = {192,168,19,199}; // IP address of WiShield {192,168,19,199};
unsigned char gateway_ip[] = {192,168,19,254}; // router or gateway IP address {192,168,19,254};
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"TDBoyanivka"}; // max 32 bytes {"TDBoyanivka"};
 
/*
unsigned char local_ip[] = {192,168,19,199}; // IP address of WiShield {192,168,19,199};
unsigned char gateway_ip[] = {192,168,19,254}; // router or gateway IP address {192,168,19,254};
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"TDBoyanivka"}; // max 32 bytes {"TDBoyanivka"};
*/
 
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"tdboyanivka"}; // max 64 characters
 
// WEP 128-bit keys
// sample HEX keys
 
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
 
 
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
 
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
    // Check if the requested URL matches "/"
    if ((strcmp(URL, "/") == 0)||(strcmp(URL, "/?1") == 0)||(strcmp(URL, "/?2") == 0)||(strcmp(URL, "/?11") == 0) ||(strcmp(URL, "/?12") == 0)){
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("<meta charset=utf-8><center>");
//      WiServer.print("<img src=http://boyanivka.com/assets/template/image/logo.png ");
        WiServer.print("<img src=http://i.biz-gid.com/img/logo/42131.jpeg >");
        WiServer.print("</html>");
        WiServer.print("<body>");
        WiServer.print("<p>-- TD Boyanivka Camera module --</p>");
        WiServer.print("<p><a href=/?1>ЛЕВЕЕ</a></p>");
        WiServer.print("<p><a href=/?2>ПРАВЕЕ</a></p>");
        WiServer.print("<p><a href=/?11>ЛЕВЕЕ НА 3</a></p>");
        WiServer.print("<p><a href=/?12>ПРАВЕЕ НА 3</a></p>");
        digitalWrite(led_pin, LOW); //delay(10); digitalWrite(led_pin, LOW);  
            if (strcmp(URL, "/?1") == 0) {
            Serial.println("DA DA DA 1");
            move_cam(1);
            }
            if (strcmp(URL, "/?2") == 0) {
            Serial.println("DA DA DA 2");
            move_cam(2);
            }
            if (strcmp(URL, "/?11") == 0) {
            Serial.println("DA DA DA 11");
            move_cam(1);delay(40);move_cam(1);delay(40);move_cam(1);
            }
            if (strcmp(URL, "/?12") == 0) {
            Serial.println("DA DA DA 12");
            move_cam(2);delay(40);move_cam(2);delay(40);move_cam(2);
            }
       // URL was recognized
    return true;
    }
    // URL not found
//    return false;
}
 
void SendImp(String S){
       String str = S;                            // ТУТ я Ваще молодец !!!
       int str_len = str.length() + 1; 
       char char_array[str_len];
       str.toCharArray(char_array, str_len);
       const char *msg = char_array ;
       vw_send((uint8_t *)msg, strlen(msg));
       vw_wait_tx();
}                                                // ТУТ я Ваще молодец !!!
 
void move_cam(int pos){
 
/* 
 if (pos == 1) {SendImp("1"); Serial.println(p); delay(150); p = 0 ;}
 if (pos == 2) {SendImp("2"); Serial.println(p); delay(150); p = 0 ;}
*/
 if (pos == 1) {SendImp("1"); Serial.println(p); delay(150); p = 0 ;}
 if (pos == 2) {SendImp("2"); Serial.println(p); delay(150); p = 0 ;}
 
}
 
void setup() {
 
   pinMode(but1, INPUT); pinMode(but2, INPUT); pinMode(wlan_but, INPUT); pinMode(led_pin, OUTPUT);
 
    vw_set_ptt_inverted(true);  // Required by the RF module
    vw_setup(2000);            // bps connection speed
    vw_set_tx_pin(transmit_pin);
    
 
  // Initialize WiServer and have it use the sendMyPage function to serve pages
if (digitalRead(wlan_but) != HIGH) { WiServer.init(sendMyPage);} // ВОТ ТУТ ПРОВЕРКА КНОПКИ ВКЛЮЧЕНИЯ 
  Serial.begin(9600);
//  WiServer.enableVerboseMode(true); // ТУТ логирование на СОМ порт
}
 
void loop(){
 
  // Run WiServer
   if (digitalRead(wlan_but) != HIGH) { 
   WiServer.server_task();
   digitalWrite(led_pin, HIGH);
 } 
// И ТУТ проверка
    if (Serial.available()){
    p = Serial.read();
    if (p == 49) { move_cam(1); }
    if (p == 50) { move_cam(2); }
  }
 
if (digitalRead(but1) == HIGH) {  digitalWrite(led_pin, LOW); SendImp("1"); Serial.println(p); delay(150); p = 0 ; }
if (digitalRead(but2) == HIGH) {  digitalWrite(led_pin, LOW); SendImp("2"); Serial.println(p); delay(150); p = 0 ; }
//  delay(10);  
  //if (digitalRead(wlan_but) != HIGH) { digitalWrite(len_pin, LOW); } 
}