Jump to content

umesh

Members
  • Content Count

    26
  • Joined

  • Last visited

  1. Hello friends I have taken the code from this link: https://hackaday.io/project/5626/logs Here very nice explanation is given about esp8266 and arduino. I am trying it with ESP8266 and MSP430g2553 using energia. But i am stuck at ERROR 13 that means all AT commands are working properly but when it try to connect to plot.ly server then at this stage error is coming The code is giving error 13 that means it has not getting response as '~' (as per the code) So anybody knows what type of error this is?? please go through below code and reply me. #define ssid "friends" #define pass "walchand" #define userName "umeshwe" #define APIKey "3yg9lnub2w" #define fileName "test" #define fileopt "overwrite" #define nTraces 1 #define maxpoints "30" #define world_readable true #define convertTimestamp true #define timezone "Indian/Cocos" #include <SoftwareSerial.h> #include <avr/pgmspace.h> #define prog_char char PROGMEM char *tokens[nTraces] = {"u6bibkxlmz"}; char stream_site[25] = {0}; SoftwareSerial mySerial(5, 6); // RX, TX const PROGMEM char cmd_0[] = {"AT\r\n"}; const PROGMEM char cmd_1[] = {"ATE1\r\n"}; const PROGMEM char cmd_2[] = {"AT+CWMODE=1\r\n"}; const PROGMEM char cmd_3[] = {"AT+CIPMODE=0\r\n"}; const PROGMEM char cmd_4[] = {"AT+RST\r\n"}; const PROGMEM char cmd_5[] = {"AT+CIPMUX=1\r\n"}; const PROGMEM char cmd_6[] = {"AT+CWJAP=\""}; const PROGMEM char cmd_7[] = {"AT+CIPCLOSE=\""}; const PROGMEM char cmd_8[] = {"AT+CIPSTART=0,\"TCP\",\""}; const PROGMEM char cmd_9[] = {"AT+CIPSEND=0,"}; const PROGMEM char resp_0[] = {"OK"}; const PROGMEM char resp_1[] = {"ready"}; const PROGMEM char resp_2[] = {"no change"}; const PROGMEM char resp_3[] = {"CONNECT"}; const PROGMEM char resp_4[] = {"Unlink"}; const PROGMEM char resp_5[] = {"Linked"}; const PROGMEM char resp_6[] = {">"}; const PROGMEM char resp_7[] = {"~"}; const PROGMEM char error[] = {"*ERROR "}; const PROGMEM char error_0[] = {"0*"}; const PROGMEM char error_1[] = {"1*"}; const PROGMEM char error_2[] = {"2*"}; const PROGMEM char error_3[] = {"3*"}; const PROGMEM char error_4[] = {"4*"}; const PROGMEM char error_5[] = {"5*"}; const PROGMEM char error_6[] = {"6*"}; const PROGMEM char error_7[] = {"7*"}; const PROGMEM char error_8[] = {"8*"}; const PROGMEM char error_9[] = {"9*"}; const PROGMEM char error_10[] = {"10*"}; const PROGMEM char error_11[] = {"11*"}; const PROGMEM char error_12[] = {"12*"}; const PROGMEM char error_13[] = {"13*"}; const PROGMEM char error_14[] = {"14*"}; const PROGMEM char error_15[] = {"15*"}; const PROGMEM char error_16[] = {"16*"}; const PROGMEM char string_0[] = {"Initializing plot with Plot.ly server...\r\n"}; const PROGMEM char string_1[] = {"\",\""}; const PROGMEM char string_2[] = {"\""}; const PROGMEM char string_3[] = {"\",80"}; const PROGMEM char string_4[] = {"POST /clientresp HTTP/1.1\r\n"}; const PROGMEM char string_5[] = {"Host: plot.ly:80\r\n"}; const PROGMEM char string_6[] = {"User-Agent: Arduino/0.6.0\r\n"}; const PROGMEM char string_7[] = {"Content-Length: "}; const PROGMEM char string_8[] = {"version=2.3&origin=plot&platform=arduino&un="}; const PROGMEM char string_9[] = {"&key="}; const PROGMEM char string_10[] = {"&args=["}; const PROGMEM char string_11[] = {"{\"y\": [], \"x\": [], \"type\": \"scatter\", \"stream\": {\"token\": \""}; const PROGMEM char string_12[] = {"\", \"maxpoints\": "}; const PROGMEM char string_13[] = {"}}"}; const PROGMEM char string_14[] = {", "}; const PROGMEM char string_15[] = {"]&kwargs={\"fileopt\": \""}; const PROGMEM char string_16[] = {"\", \"filename\": \""}; const PROGMEM char string_17[] = {"\", \"world_readable\": "}; const PROGMEM char string_18[] = {"true"}; const PROGMEM char string_19[] = {"false"}; const PROGMEM char string_20[] = {"}"}; const PROGMEM char string_21[] = {"Successfully Initialized.\r\n"}; const PROGMEM char string_22[] = {"Please visit: \"http://plot.ly/~"}; const PROGMEM char string_23[] = {"\"."}; const PROGMEM char string_24[] = {"POST / HTTP/1.1\r\n"}; const PROGMEM char string_25[] = {"Host: arduino.plot.ly\r\n"}; const PROGMEM char string_26[] = {"User-Agent: Arduino\r\n"}; const PROGMEM char string_27[] = {"Transfer-Encoding: chunked\r\n"}; const PROGMEM char string_28[] = {"Connection: close\r\n"}; const PROGMEM char string_29[] = {"plotly-convertTimestamp: \"Australia/Melbourne\"\r\n\r\n"}; const PROGMEM char string_30[] = {"\r\n{\"x\": "}; const PROGMEM char string_31[] = {", \"y\": "}; const PROGMEM char string_32[] = {", \"streamtoken\": \""}; const PROGMEM char string_33[] = {"\"}\n\r\n0\r\n\r\n"}; const char* const resp_table[] PROGMEM = {resp_0, resp_1, resp_2, resp_3, resp_4, resp_5, resp_6, resp_7}; char buffer[20]={0}; /* -------------- Setup ------------------ */ void setup() { // Setup Serial mySerial.begin(9600); Serial.begin(115200); Serial.setTimeout(8000); delay(1000); ESP8266_Init(); plotly_init(); ESP8266_Disconnect(0); // Making sure disconnected ESP8266_Connect("arduino.plot.ly"); } /* ------------- Loop -------------------- */ void loop() { mySerial.println("Reading ADC..."); int val = analogRead(0); mySerial.println("Sending Jason..."); plotly_plot(millis(),val,tokens[0]); } /* --------------- Functions -------------------- */ void mySerial_PrintConstString(const prog_char str[]) { char c; if(!str) return; while((c = pgm_read_byte(str++))) mySerial.write©; } void Serial_PrintConstString(const prog_char str[]) { char c; if(!str) return; while((c = pgm_read_byte(str++))) Serial.write©; } boolean find_resp(unsigned char a, const prog_char error_str[]){ strcpy_P(buffer, (char*)pgm_read_word(&(resp_table[a]))); if(!Serial.find(buffer)){ mySerial_PrintConstString(error); mySerial_PrintConstString(error_str); mySerial.println(); return false; } else{ return true; } } void ESP8266_Init(){ mySerial_PrintConstString(string_0); // send debug "Initializing plot with Plot.ly server...\r\n" // Startup test Serial_PrintConstString(cmd_0); // send "AT\r\n" if(!find_resp(0,error_0)){while(1){}} // find "OK" // Turn ECHO off // Serial_PrintConstString(cmd_1); // send "ATE1\r\n" //if(!find_resp(0,error_1)){while(1){}} // find "OK" // Put WiFi into Station mode Serial_PrintConstString(cmd_2); // send "AT+CWMODE=1\r\n" if(!find_resp(0,error_2)){ // find "no change" Serial_PrintConstString(cmd_2); // send "AT+CWMODE=1\r\n" if(!find_resp(0,error_3)){while(1){}} // find "OK" } // Set data transmission mode to no data (0) // Serial_PrintConstString(cmd_3); // send "AT+CIPMODE=0\r\n" // if(!find_resp(0,error_4)){while(1){}} // find "OK" // Restart ESP8266 Serial_PrintConstString(cmd_4); // send "AT+RST\r\n" if(!find_resp(1,error_5)){while(1){}} // find "IP" // Enable multiple connections (MUX) Serial_PrintConstString(cmd_5); // send "AT+CIPMUX=1\r\n" if(!find_resp(0,error_6)){while(1){}} // find "OK" Serial_PrintConstString(cmd_6); // send "AT+CWJAP=\" Serial.print(ssid); // send ssid Serial_PrintConstString(string_1); // send "\",\"" Serial.print(pass); // send password Serial_PrintConstString(string_2); // send "\"" Serial.println(); if(!find_resp(0,error_7)){while(1){}} // find "OK" } void ESP8266_Disconnect(unsigned char id){ Serial_PrintConstString(cmd_7); // send "AT+CIPCLOSE=\"" Serial.print(id); // send id Serial_PrintConstString(string_2); // send "\"" Serial.println(); if(!find_resp(4,error_8)){ // find "Unlink" Serial_PrintConstString(cmd_7); // send "AT+CIPCLOSE=\"" Serial.print(id); // send id Serial_PrintConstString(string_2); // send "\"" Serial.println(); while(1){} } } void ESP8266_Connect(char *url){ int p = (int)url; Serial_PrintConstString(cmd_8); // send "AT+CIPSTART=0,\"TCP\",\"" url = (char *)p; while(*url){ // send URL Serial.print(*url); url++; } Serial_PrintConstString(string_3); // send "\",80" Serial.println(); if(!find_resp(0,error_9)){ // find "Linked" Serial_PrintConstString(cmd_8); // send "AT+CIPSTART=0,\"TCP\",\"" url = (char *)p; while(*url){ // send URL Serial.print(*url); url++; } Serial_PrintConstString(string_3); // send "\",80" Serial.println(); if(find_resp(3,error_10)){ // find "CONNECT" ESP8266_Disconnect(0); Serial_PrintConstString(cmd_8); // send "AT+CIPSTART=0,\"TCP\",\"" url = (char *)p; while(*url){ // send URL Serial.print(*url); url++; } Serial_PrintConstString(string_3); // send "\",80" Serial.println(); if(!find_resp(5,error_11)){while(1){}} // find "Linked" } } } void plotly_init(){ unsigned int i = 0; char charbuffer; unsigned int contentLength = 126 + strlen(userName) + strlen(fileopt) + nTraces*(87+strlen(maxpoints)) + (nTraces - 1)*2 + strlen(fileName); if(world_readable){ contentLength += 4; } else{ contentLength += 5; } String contentLengthString = String(contentLength); const char* contentLengthConstString = contentLengthString.c_str(); unsigned int postLength = contentLength + 94 + strlen(contentLengthConstString); ESP8266_Connect("plot.ly"); Serial_PrintConstString(cmd_9); // send "AT+CIPSEND=0," Serial.println(postLength); if(find_resp(6,error_12)){ // find ">" Serial_PrintConstString(string_4); // send "POST /clientresp HTTP/1.1\r\n" Serial_PrintConstString(string_5); // send "Host: plot.ly:80\r\n" Serial_PrintConstString(string_6); // send "User-Agent: Arduino/0.6.0\r\n" Serial_PrintConstString(string_7); // send "Content-Length: " Serial.print(contentLength); Serial.println(); Serial.println(); Serial_PrintConstString(string_8); // send "version=2.3&origin=plot&platform=arduino&un=" Serial.print(userName); // send userName Serial_PrintConstString(string_9); // send "&key=" Serial.print(APIKey); // send APIKey Serial_PrintConstString(string_10); // send "&args=[" for(int i=0; i<nTraces; i++){ Serial_PrintConstString(string_11); // send "{\"y\": [], \"x\": [], \"type\": \"scatter\", \"stream\": {\"token\": \"" Serial.print(tokens); // send token Serial_PrintConstString(string_12); // send "\", \"maxpoints\": " Serial.print(maxpoints); // send maxpoints Serial_PrintConstString(string_13); // send "}}" if(nTraces > 1 && i != nTraces-1){ Serial_PrintConstString(string_14); // send ", " } } Serial_PrintConstString(string_15); // send "]&kwargs={\"fileopt\": \"" Serial.print(fileopt); // send fileopt Serial_PrintConstString(string_16); // send "\", \"filename\": \"" Serial.print(fileName); // send fileName Serial_PrintConstString(string_17); // send "\", \"world_readable\": " if(world_readable){ Serial_PrintConstString(string_18); // send "true" } else{ Serial_PrintConstString(string_19); // send "false" } Serial_PrintConstString(string_20); // send "}" Serial.println(); if(find_resp(7,error_13)){ // find "~" i=0; while(1){ while(!Serial.available()){} charbuffer = Serial.read(); if(charbuffer == 34){break;} stream_site = charbuffer; i++; } if(!find_resp(0,error_14)){ // find "OK" while(1){} } mySerial_PrintConstString(string_21); // send debug "Successfully Initialized.\r\n" mySerial_PrintConstString(string_22); // send debug "Please visit: \"http://plot.ly/~" i=0; while(stream_site){ mySerial.print(stream_site); i++; } mySerial_PrintConstString(string_23); // send debug "\"." mySerial.println(); } else{ while(1){} } } else{ while(1){} } } void plotly_plot(unsigned long x, int y, char *token){ String xString = String(x); String yString = String(y); const char* xConstString = xString.c_str(); const char* yConstString = yString.c_str(); unsigned int jasonLength = 44 + strlen(xConstString) + strlen(yConstString); String jasonLengthString = String(jasonLength, HEX); const char* ConstJasonLengthString = jasonLengthString.c_str(); unsigned int postLength = 167 + strlen(ConstJasonLengthString) + jasonLength; Serial_PrintConstString(cmd_9); // send "AT+CIPSEND=0," Serial.println(postLength); if(find_resp(6,error_15)){ // find ">" Serial_PrintConstString(string_24); // send "POST / HTTP/1.1\r\n" Serial_PrintConstString(string_25); // send "Host: arduino.plot.ly\r\n" Serial_PrintConstString(string_26); // send "User-Agent: Arduino\r\n" Serial_PrintConstString(string_27); // send "Transfer-Encoding: chunked\r\n" Serial_PrintConstString(string_28); // send "Connection: close\r\n" Serial_PrintConstString(string_29); // send "plotly-convertTimestamp: \"Australia/Melbourne\"\r\n\r\n" } else{ while(1){} } Serial.print(jasonLengthString); Serial_PrintConstString(string_30); // send "\r\n{\"x\": " Serial.print(x); // send x Serial_PrintConstString(string_31); // send ", \"y\": " Serial.print(y); // send y Serial_PrintConstString(string_32); // send ", \"streamtoken\": \"" while(*token){ // send token Serial.print(*token); token++; } Serial_PrintConstString(string_33); // send "\"}\n\r\n" if(find_resp(0,error_16)){ // find "OK" mySerial.println("Sent data!"); } else{ mySerial.println("*Couldn't send data!!*"); } }
  2. Hello yosh I tried by connecting ESP to Hardware UART as per you suggest and i use software UART for debugging. The code is as follows: #include <SoftwareSerial.h> SoftwareSerial dbgSerial(5,6); // make RX MSP line is pin 5, make TX MSP line is pin 6. // This means that you need to connect the TX line from the esp to the MSP's pin 5 // and the RX line from the esp to the MSP's pin 6 void setup() { Serial.begin(115200); dbgSerial.begin(9600); // your esp's baud rate might be different } void loop() { if(Serial.available()) // check if the esp is sending a message { while(Serial.available()) { // The esp has data so display its output to the serial window char c = Serial.read(); // read the next character. dbgSerial.write©; } } if(dbgSerial.available()) { // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it // but we want to send everything at the same time. delay(1000); String command=""; while(dbgSerial.available()) // read the command character by character { // read one character command+=(char)dbgSerial.read(); } Serial.println(command); // send the read character to the esp8266 } } and i got the response but it is not in standard format. For "AT+RST" command it is giving response as: A b OSCO 8cau m 0096 taim 0xle l0en cebe0oDOaKue {
  3. Hello everybody, Now i am able to communicate MSP430G2553 with ESP8266 and ESP8266 is giving response for AT commands.I am using software UART to communicate with ESP and hardware UART for debugging. So unfortunately it is printing garbage characters. I think it can be the problem of baud rate mismatch. ESP8266 default baud rate is 115200 and software UART is supports upto 9600. The code for checking AT command response taken from internet is as follows: #include <SoftwareSerial.h> SoftwareSerial esp8266(5,6); // make RX msp430g2553 line is pin 5, make TX msp430g2553 line is pin 6. // This means that you need to connect the TX line from the esp to the msp430g2553's pin 2 // and the RX line from the esp to the msp430g2553's pin 3 void setup() { Serial.begin(9600); esp8266.begin(115200); // your esp's baud rate might be different } void loop() { if(esp8266.available()) // check if the esp is sending a message { while(esp8266.available()) { // The esp has data so display its output to the serial window char c = esp8266.read(); // read the next character. Serial.write(c); } } if(Serial.available()) { // the following delay is required because otherwise the msp430g2553 will read the first letter of the command but not the rest // In other words without the delay if you use AT+RST, for example, the msp430g2553 will read the letter A send it, then read the rest and send it // but we want to send everything at the same time. delay(1000); String command=""; while(Serial.available()) // read the command character by character { // read one character command+=(char)Serial.read(); } esp8266.println(command); // send the read character to the esp8266 } } So how can i use hardware UART to communicate with esp. Or how can i change baudrate of esp to 9600? Thank you.
  4. Hello everybody, I have solved the power supply problem for ESP8266. I have given 3.3V 500mA power externally to esp8266. But now i facing the problem to communicate msp430g2553 with esp8266. I made the connections as follows: Tx of ESP to Rx of Launchpad Rx of ESP to Tx of Launchpad VCC to Vcc Gnd to Gnd CH_PD to 3.3V GPIO0 to 3.3 V and i uploaded blank sketch i.e. Bare minimum from example, but i didn't get any response for AT commands. What should i make changes in order to get proper response. When i reset the esp then garbage value is shown on serial monitor. I have checked by changing all possible baud rates as well as swap TX and RX pins. Thanks and regards
  5. Hello, Whether we have to add some libraries of ESP8266 to the energia or not? if yes then which are those? When i using above code then it compiles and loaded finely but not giving response. It prints AT+RST on serial monitor.
  6. i got the code from below link and they said that code working finely with no bugs. http://forum.43oh.com/topic/5903-esp8266-iot-on-the-cheap/ They didn't mention any power related issue. So really can it be only power supply issue? or baud rate mismatch? I update the esp8266 firmware also to operate with Arduino board
  7. Yes i tried connecting esp directly to pc and its working fine. I was able to send data to browser without any problem. But it is not working with MSP430 launchpad. Now i will try by giving sufficient power to esp8266.
  8. Hello I am trying to send data to browser using wifi module ESP8266 with MSP430G2553 launchpad. ESP8266 work on 3.3V and MSP430G2553 also. So here i connected ESP8266 directly to the launchpad. connections are- Tx of ESP to Rx of Launchpad Rx of ESP to Tx of Launchpad VCC to Vcc Gnd to Gnd CH_PD to 3.3V and i got code for energia from this forum only. code is as follows #define SSID "friends" #define PASS "walchand" #define DST_IP "things.ubidots.com" #define idvariable "569fc4ba76254229c49896a6" // replace with your Ubidots Variable ID #define token "aIdUatYb4QqgntExGmdi6xIllonUaY3AxwJjs5UzCCVib9reI1dI2XFEnfeX" // replace with your Ubidots token int len; void setup() { // Open serial communications and wait for port to open: char cmd[254]; Serial.begin(9600); Serial.setTimeout(5000); //test if the module is ready Serial.println("AT+RST"); delay(1000); if (Serial.find("ready")) { Serial.println("Module is ready"); } else { Serial.println("Module have no response."); while (1); } delay (1000); //connect to the wifi boolean connected = false; for (int i = 0; i < 5; i++) { if (connectWiFi()) { connected = true; break; } } if (!connected) { while (1); } delay(5000); Serial.println("AT+CIPMUX=0"); } void loop() { int value = analogRead(A0); //you can change ir to another pin int num=0; String var = "{\"value\":"+ String(value) + "}"; num = var.length(); String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += DST_IP; cmd += "\",80"; Serial.println(cmd); if (Serial.find("Error")) return; len=strlen ("POST /api/v1.6/datasources/"); len=len+strlen (idvariable); len=len+strlen ("/values HTTP/1.1\nContent-Type: application/json\nContent-Length: "); char numlenght[4]; // this will hold the length of num which is the length of the JSON element sprintf(numlenght, "%d", num); // saw this clever code off the net; works yay len=len+strlen (numlenght); len=len + num; //fixed length of the string that will print as Content-Length: in the POST len=len+strlen ("\nX-Auth-Token: "); len=len+strlen (token); len=len+strlen ("\nHost: things.ubidots.com\n\n"); len=len+strlen ("\n\n"); Serial.print("AT+CIPSEND="); Serial.println (len); //lenght of the entire data POST for the CIPSEND command of ESP2866 //Serial.println(cmd.length()); if (Serial.find(">")) { //Serial.print(">"); } else { Serial.println("AT+CIPCLOSE"); delay(1000); return; } Serial.print ("POST /api/v1.6/variables/"); Serial.print (idvariable); Serial.print ("/values HTTP/1.1\nContent-Type: application/json\nContent-Length: "); Serial.print (num); Serial.print ("\nX-Auth-Token: "); Serial.print (token); Serial.print ("\nHost: things.ubidots.com\n\n"); Serial.print (var); Serial.println ("\n\n"); delay(9000); //Serial.find("+IPD"); clear the input buffer after the web site responds to the POST while (Serial.available()) { char c = Serial.read(); } delay(1000); } boolean connectWiFi() { Serial.println("AT+CWMODE=1"); String cmd = "AT+CWJAP=\""; cmd += SSID; cmd += "\",\""; cmd += PASS; cmd += "\""; Serial.println(cmd); delay(2000); if (Serial.find("OK")) { return true; } else { return false; } } when i trying to connect to wifi then it is not working properly it display only .. AT+RST Module have no response. So what can be the problem?? And one more thing is that blue LED on ESP is not blinking continuously.
  9. ok thank you i tried the above code and it working fine.. i am doing the project of smart sensor data acquisition module for acoustic emission sensor with wireless communication. I want to make my module smart by adding various features like temperature compensation, self-calibration, input detection, webpage access, Plug n play etc. and other also can be included. i don't know much about tm4c1294 connected launchpad. So how many features are there and what can we do with this launchpad to make my data acquisition system smart. Please give me some ideas and suggest me some examples of tm4c1294 in energia. Thank you
  10. can anybody give me working code in energia for internal temperature sensor for tm4c1294 connected launchpad.
  11. Another thing is i want to send data using bluetooth through UART. I tried for it but it won't work properly. I did it correctly on MSP430G2553 Launchpad but it was not working on TM4C1294 connected launchpad. is there any extra setting required due to more no of UART and multi function pins?? Plz tell me how to do in Energia.. Thanks..
×
×
  • Create New...