Skip to content

Commit

Permalink
Merge pull request #3 from anakod/master
Browse files Browse the repository at this point in the history
Merge upstream changes.
  • Loading branch information
tavalin committed Jul 1, 2015
2 parents 443281a + 29dfa9f commit 17b1b11
Show file tree
Hide file tree
Showing 15 changed files with 1,711 additions and 36 deletions.
20 changes: 20 additions & 0 deletions IR_lib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#####################################################################
#### Please don't change this file. Use Makefile-user.mk instead ####
#####################################################################
# Including user Makefile.
# Should be used to set project-specific parameters
include ./Makefile-user.mk

# Important parameters check.
# We need to make sure SMING_HOME and ESP_HOME variables are set.
# You can use Makefile-user.mk in each project or use enviromental variables to set it globally.

ifndef SMING_HOME
$(error SMING_HOME is not set. Please configure it in Makefile-user.mk)
endif
ifndef ESP_HOME
$(error ESP_HOME is not set. Please configure it in Makefile-user.mk)
endif

# Include main Sming Makefile
include $(SMING_HOME)/Makefile-project.mk
30 changes: 30 additions & 0 deletions IR_lib/Makefile-user.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Local build configuration
## Parameters configured here will override default and ENV values.
## Uncomment and change examples:

#Add your source directories here separated by space
MODULES = app

## ESP_HOME sets the path where ESP tools and SDK are located.
## Windows:
# ESP_HOME = c:/Espressif

## MacOS / Linux:
#ESP_HOME = /opt/esp-open-sdk

## SMING_HOME sets the path where Sming framework is located.
## Windows:
# SMING_HOME = c:/tools/sming/Sming

# MacOS / Linux
# SMING_HOME = /opt/sming/Sming

## COM port parameter is reqruied to flash firmware correctly.
## Windows:
# COM_PORT = COM3

# MacOS / Linux:
# COM_PORT = /dev/tty.usbserial

# Com port speed
# COM_SPEED = 115200
40 changes: 40 additions & 0 deletions IR_lib/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************
A simple example on how to use the IR library
****************************************************/

#include <user_config.h>
#include <SmingCore/SmingCore.h>
#include <Libraries/IR/IRremote.h>
#include <Libraries/IR/IRremoteInt.h>

#define IR_PIN 12 // GPIO12

Timer irTimer;
decode_results dresults;
IRrecv irrecv(IR_PIN);
IRsend irsend;

void receiveIR()
{
if(irrecv.decode(&dresults)==DECODED){
irTimer.stop();
unsigned int * sendbuff = new unsigned int[dresults.rawlen-1];
for(int i=0; i<dresults.rawlen-1; i++){
sendbuff[i]=dresults.rawbuf[i+1]*50;
}
irsend.sendNEC(dresults.value, dresults.bits);
Serial.println("Sent IR Code");
irrecv.enableIRIn();
irTimer.start();
}
}

void init()
{
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.println("Setting up...");
irrecv.blink13(1);
irrecv.enableIRIn(); // Start the receiver
irTimer.initializeMs(1000, receiveIR).start();
Serial.println("Ready...");
}
45 changes: 45 additions & 0 deletions IR_lib/include/user_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef __USER_CONFIG_H__
#define __USER_CONFIG_H__

#ifdef __cplusplus
extern "C" {
#endif
// UART config
#define SERIAL_BAUD_RATE 115200

// ESP SDK config
#define LWIP_OPEN_SRC
#define USE_US_TIMER

// Default types
#define __CORRECT_ISO_CPP_STDLIB_H_PROTO
#include <limits.h>
#include <stdint.h>

// Override c_types.h include and remove buggy espconn
#define _C_TYPES_H_
#define _NO_ESPCON_

// Updated, compatible version of c_types.h
// Just removed types declared in <stdint.h>
#include <espinc/c_types_compatible.h>

// System API declarations
#include <esp_systemapi.h>

// C++ Support
#include <esp_cplusplus.h>
// Extended string conversion for compatibility
#include <stringconversion.h>
// Network base API
#include <espinc/lwip_includes.h>

// Beta boards
#define BOARD_ESP01

#ifdef __cplusplus
}
#endif

#endif
17 changes: 14 additions & 3 deletions MqttClient_Hello/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#define WIFI_PWD "PleaseEnterPass"
#endif

void onMessageReceived(String topic, String message); // Forward declaration for our callback
// Forward declarations
void startMqttClient();
void onMessageReceived(String topic, String message);

Timer procTimer;

Expand All @@ -18,6 +20,9 @@ MqttClient mqtt("test.mosquitto.org", 1883, onMessageReceived);
// Publish our message
void publishMessage()
{
if (mqtt.getConnectionState() != eTCS_Connected)
startMqttClient(); // Auto reconnect

Serial.println("Let's publish message now!");
mqtt.publish("main/frameworks/sming", "Hello friends, from Internet of things :)"); // or publishWithQoS
}
Expand All @@ -30,14 +35,20 @@ void onMessageReceived(String topic, String message)
Serial.println(message);
}

// Run MQTT client
void startMqttClient()
{
mqtt.connect("esp8266");
mqtt.subscribe("main/status/#");
}

// Will be called when WiFi station was connected to AP
void connectOk()
{
Serial.println("I'm CONNECTED");

// Run MQTT client
mqtt.connect("esp8266");
mqtt.subscribe("main/status/#");
startMqttClient();

// Start publishing loop
procTimer.initializeMs(20 * 1000, publishMessage).start(); // every 20 seconds
Expand Down
Loading

0 comments on commit 17b1b11

Please sign in to comment.