Close

More playing around with a mcu connected to an ESP8266

A project log for HouseRemote

Remotely monitor and control appliances from anywhere!

mcunerdmcu_nerd 11/04/2015 at 16:330 Comments

Yes, I'm still here! I've figured out my own way to do bi-directional communication (sort of) between my MSP430G2553 connected to an ESP8266 and my web server. The MSP430 sending temp data to my web server is nice, but I wanted to come up with a way to send commands back to the MSP430 without having to dump the default AT firmware on the ESP8266.

Here is how it works in a nutshell:

There is a text file on the webserver that contains a character that represents a command (that's to be updated via the web control interface, haven't done that part yet)

The ESP8266 essentially polls that textfile every so often, and if it finds one of several particular characters, it runs the associated command (such as turn on an LED)

It's a hack job, but it does work: Energia sketch below:

char starry[170];
void setup()
{
  // put your setup code here, to run once:
P1OUT &=~B01000001;
P1DIR |=BIT0;
P1DIR |=BIT6;
delay(6000);
Serial.begin(115200);  
}

void loop()
{
  // put your main code here, to run repeatedly:
delay(500);
querycommand();
}

void querycommand(){
Serial.print("ATE0\r\n"); //disables local echo
delay(50);
Serial.print("AT+CIPSTART=\"TCP\",\"192.168.18.5\",80\r\n");  
 delay(50);
Serial.print("AT+CIPSEND=");
Serial.print(26);
Serial.print("\r\n");
delay(50);

Serial.print("GET /nextgen/command.txt\r\n\r\n");//26

int count=0;
if (Serial.available()){
  if(Serial.find("+IPD")){
  P1OUT |=BIT6;
    while(count<170){
  starry[count]=Serial.read();
count++; 
  }
   }
}
count=0;
while(count < 170){
 if(starry[count] =='8'){
    P1OUT |=BIT0;
    count=170;
  }
 else if(starry[count]=='z'){
  P1OUT &=~BIT0;
  count=170;
 } 
 else{
  count++;
 } 
}
}

Discussions