Jump to content
43oh

ESP8266 - IoT on the cheap ;)


Recommended Posts

Hi everybody,

 

People might have read the hackaday post describing the ESP8266. The ESP8266 is a really low price Wifi chip, which uses serial communication (just like the Wifly etc.) to connect to wifi. Although the CC3100 and CC3200 are the better chips, the ESP8266 main differentiating point is its ridiculous low price. I've ordered 8 for $3.50 each (aliexpress). It doesn't seem to support IPv6 out of the box, but there is an SDK, which might open future possibilities.

 

I was thinking to make a library for energia to support the ESP8266. Anyone interested? Are there specific starting points to make this library usable?

 

I am looking at two scenario's:

- MQTT client - Relaying sensor data or control.

- Web service - Returning a JSON object with sensor data.

 

It would be nice to use the hooks of an ethernet library and only need to process strings/arrays of bytes. 

 

Edit: As this wifi dongle uses an UART, how do I create two UARTS on a G2553?

 

Kind regards,

 

Eelco Rouw

Link to post
Share on other sites

So this device has a low power 32 bit CPU in it.  What is the point of an MSP430 connected to it?

(i.e., if you add the G2553, e.g., as a peripheral to this device, what does the MSP430 bring to the setup.)

 Most boards for the esp only have 2 gpio broken out, lack of technical data, sdk, etc.

Link to post
Share on other sites

Hi everybody,

 

The modules are quite easy to connect and configure. Although the wifi dongle has its own microcontroller, I want to use it with the launchpad. I am not looking to tweak the modules themselves but create simple connected devices. The combination of a value line controller and the ESP8266 yields cheap smart switches and smart objects. 

 

Still pondering how the library should be structured...

 

Kind regards, 

 

Eelco

Link to post
Share on other sites
  • 3 weeks later...

Another alternative - EMW3162.

Uses Cortex M3 (STM32F205RG) (for those put off by the less common CPU of the ESP8266).
 
Looks like it could be a less expensive ($8.50), more powerful (120MHz, 1M byte of Flash, 128k bytes) alternative to the CC3200.
No desire to hijack this thread, but would be curious about comparison between the three platforms.

I started a thread on this on stellarisiti, but it seems to be slow showing up.

Link to post
Share on other sites
  • 4 months later...

after fighting with the terrible string handling of msp430-g++ I finally got ESP8266 to work with MSP430 G2553 and upload telemetry data to ubidots. This is a REAL working code, no BS. Thanks to all who suggested using standard c str instead of the "String" object. 

       
        
        #define SSID        "xxxx"
        #define PASS        "xxxxx"
        #define DST_IP      "things.ubidots.com"
        #define idvariable  "xxxxxxxx"   // replace with your Ubidots Variable ID
        #define token       "xxxxxxxxxxxxx"  // replace with your Ubidots token
        int len;
        
        void setup()
        {
          // Open serial communications and wait for port to open:
          char cmd[254];
          Serial.begin(115200);
          Serial.setTimeout(5000);
          //test if the module is ready
          Serial.println("AT+RST");
          delay(1000);
          if (Serial.find("ready"))
          {
            //dbgSerial.println("Module is ready");
          }
          else
          {
            //dbgSerial.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;
          }
        } 
        
Link to post
Share on other sites

@@bubba198 You do see that you're still using String instead of c-style strings?

 

Also, you're using Serial.print() while also using '\n', though sometimes you use println().

//This code
          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");

// Could also be this code
          Serial.print  ("POST /api/v1.6/variables/");
          Serial.print  (idvariable);
          Serial.println("/values HTTP/1.1");
          Serial.println("Content-Type: application/json");
          Serial.print  ("Content-Length: ");
          Serial.println(num);
          Serial.print  ("X-Auth-Token: ");
          Serial.println(token);
          Serial.println("Host: things.ubidots.com");
          Serial.println("");
          Serial.print  (var);
          Serial.println("");
          Serial.println("");

Although the second looks a bit more messy, you're splitting the headerlines in a crisp fashion. It's just style, I just like the second one better.

Link to post
Share on other sites
  • 5 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...