Jump to content
Sign in to follow this  


Recommended Posts

I am working on code related to sending an email through cc3100booster and msp432p401r. I am having an issue in connectivity of wifi in the module when the wifi connection code is provided in void setup(). I am providing mobile's hotspot and it gets connected and disconnected periodically. I require an continuous connection.

When the wifi connection code is written inside loop(), the connection problem is solved but a newer issue is arised i,e, the program is running for email but not for the server [In server program i am sending temperature and pulse count value to thingspeak.com to get a graphical representation of my data.]

moreover, despite of being present in loop, it executes only once. its a complete arcane issue for me. I am linking code below. please help me out with this.

#define TEMBOO_ACCOUNT "xxxxxxx"  // your Temboo account name
#define TEMBOO_APP_KEY_NAME "xxxxxxx"  // your Temboo app name
#define TEMBOO_APP_KEY  "xxxxxxxx"  // your Temboo app key
#define WIFI_SSID "xxxxxx"   //hotspot name
#define WIFI_PASSWORD "xxxxxxx"   //hotspot password
#ifndef __CC3200R1M1RGC__
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <Temboo.h>
const String GMAIL_USER_NAME = "xxxxxxx"; //sender's email
const String GMAIL_APP_PASSWORD = "xxxxxx" //sender's app password
const String TO_EMAIL_ADDRESS = "xxxxxxx";    //receiver's email
boolean attempted = false;
#include <LiquidCrystal.h>
LiquidCrystal lcd(13,33,12,24,5,25,6,26,27,8,28);
  float temp;
  float volt;
  int sensorValue1;
  int sensorValue2;
  int count;
WiFiClient client;
char server[] = "api.thingspeak.com";
unsigned long lastConnectionTime = 0;            // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
void checkconnection()
  int wifiStatus = WL_IDLE_STATUS;
  // determine if the WiFi Shield is present.
  if (WiFi.status() == WL_NO_SHIELD) {
    // if there's no WiFi shield, stop here.
  while(wifiStatus != WL_CONNECTED) {
    wifiStatus = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    if (wifiStatus == WL_CONNECTED) {
    } else {
   Serial.println("Waiting for an ip address");
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
  Serial.println("\nIP Address obtained");
  // We are connected and have an IP address.
  // Print the WiFi status.
void serverprog()
 while (client.available()) {
    char c = client.read();
 if (millis() - lastConnectionTime > postingInterval) {
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    char msgg[200];
    sprintf(msgg,"GET /update?api_key=xxxxxxxxxxxxxxxx&field1=%f&field2=%d",temp,count);  //have to make account on thingspeak.com and create channel then create 2 fields. then copy the WRITE API key in place of xxxxxxxxx
    // send the HTTP PUT request:
    client.println("Host: api.thingspeak.com");
    client.println("User-Agent: Energia/1.1");
    client.println("Connection: close");
    // note the time that the connection was made:
    lastConnectionTime = millis();
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  // print your WiFi IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(" dBm");
   void setup() {
  lcd.begin(16, 2);
void loop() {
  int sensorValue1 = analogRead(A0);
 /* lcd.setCursor(0,0);
  lcd.print("temperature =");
 int sensorValue2;
  unsigned long start=millis();
  unsigned long currentValue;
  float x=0;
  int y;
    int sensorValue2 = analogRead(A1);
    if(sensorValue2 > x)
else if(sensorValue2 < x)
 lcd.print("temperature =");
  lcd.print("pulse count =");
   Serial.println("pulse count=");
  if (!attempted) {
    Serial.println("Running SendAnEmail...");
    TembooChoreo SendEmailChoreo(client);
    SendEmailChoreo.addInput("Username", GMAIL_USER_NAME);
    SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD);
    SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS);
    SendEmailChoreo.addInput("Subject", "Recieved An Email???");
  char msg[100];
  sprintf (msg," Body Temperature=%f, Pulse count=%d",temp,count);
    SendEmailChoreo.addInput("MessageBody", msg);
       unsigned int returnCode = SendEmailChoreo.run();
    if (returnCode == 0) {
        Serial.println("Success! Email sent!");
    } else {
           while (SendEmailChoreo.available()) {
        char c = SendEmailChoreo.read();

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this