Example #1
0
/**
 * \brief Initialize SSD1306 controller and LCD display.
 * It will also write the graphic controller RAM to all zeroes.
 *
 * \note This function will clear the contents of the display.
 */
void gfx_mono_ssd1306_init(void)
{
	uint8_t page;
	uint8_t column;

#ifdef CONFIG_SSD1306_FRAMEBUFFER
	gfx_mono_set_framebuffer(framebuffer);
#endif

	/* Initialize the low-level display controller. */
	ssd1306_init();

	/* Set display to output data from line 0 */
	ssd1306_set_display_start_line_address(0);

	/* Clear the contents of the display.
	 * If using a framebuffer (SPI interface) it will both clear the
	 * controller memory and the framebuffer.
	 */
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) {
			gfx_mono_ssd1306_put_byte(page, column, 0x00, true);
		}
	}
}
/**
 * \brief Initialize NULL driver.
 */
void gfx_mono_null_init(void)
{
	gfx_mono_set_framebuffer(framebuffer);
}
Example #3
0
int main(void)
{
	//
	asm("nop");
	rtc_init();


	//changing the clock to 32MHz
	enable_oscillator(OSC_RC32MEN_bm);
	sysclk_prescaler(CLK_PSADIV_1_gc,CLK_PSBCDIV_1_1_gc);
	sysclk_source(CLK_SCLKSEL_RC32M_gc);

	usart_config(&USARTC0,&PORTC,USART_CMODE_ASYNCHRONOUS_gc,USART_PMODE_DISABLED_gc,USART_CHSIZE_8BIT_gc,false,false);
	usart_baud(&USARTC0,9600,-3);
	FILE my_stdio;
	create_file_stream(&my_stdio,&USARTC0_putchar,&USARTC0_getchar);
	set_stdio_stream(&my_stdio);



	port_direction_set_mask(&PORTR,1<<0);

	uint8_t page;
	uint8_t column;

	gfx_mono_set_framebuffer(framebuffer);

	ssd1306_init();
	ssd1306_clear();

	ssd1306_set_display_start_line_address(0);


	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) {
			gfx_mono_ssd1306_put_byte(page, column, 0x00, 1);
		}
	}

	ssd1306_set_page_address(0);
	ssd1306_write_text("EMON");

	rtc_ms_delay(1000);

	lcd_line_print(0,"EMON YOU ROCK");

	esp8266_serial_init();

	printf("starting system\n");
	
	printf("-----------------------------------------------------------\n");

#define mqtt_callback_on_message "function(conn, topic, data) print(topic .. \":\" ) if data ~= nil then print(data) end end"

// 
	//esp8266_getmode();
	esp8266_setmode(ESP8266_WIFI_MODE_STATION);
	esp8266_available_AP_t myAPdata[10];
	int n = esp8266_sta_getap(3000,myAPdata);
	
	for(int i=0;i<n;i++){
		printf("available ssid : %s\n" , myAPdata[i].BSSID);
	}
	
	
	esp8266_sta_config("Emon","19031992",NULL,NULL);
	printf("\nthe wifi mode is %d\n", esp8266_getmode());
	esp8266_sta_getmac();

 
  	//esp8266_uart_setup(0,9600,8,ESP8266_UART_PARITY_NONE,ESP8266_UART_STOPBITS_1,0);
// 
 	esp8266_sta_getip();
 	esp8266_sta_get_status();
	lcd_line_print(0,"HABIBUR RAHMAN");
// 	
	esp8266_mqtt_create_client("m","clientid", 30 , "user", "password");
	esp8266_mqtt_client_connect("m","emon.dlinkddns.com",9000,0,"function(conn) print(\"m:connected\") end");
	esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end");
	esp8266_mqtt_client_callback_on_message("m",mqtt_callback_on_message);
	
	
	esp8266_mqtt_create_client("n","clientid", 30 , "user", "password");
	esp8266_mqtt_client_connect("n","broker.hivemq.com",1883,0,"function(conn) print(\"n:connected\") end");
	esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end");
	esp8266_mqtt_client_callback_on_message("n",mqtt_callback_on_message);
	
	int i=0;
	char numstr[30];
	char mydata[100];  
	char mydata2[100]; 
	
	char tempcmd[50]; 
	char tempdata[100];  
	while (1)
    {

		esp8266_rx_buff_receive(mydata);
		if(!strcmp(mydata, "sky2:\r\nkaminey\r\n")){
			printf("\n\n******f**k you*****\n\n");
			
			esp8266_mqtt_client_publish("m","sky","test reply .. by emon",0,0,"function(conn) print(\"sent\") end");
			printf(mydata2);
		}
		else if(!strcmp(mydata, "m:connected\r\n")){
			printf("RECONNECTING NOWWWWW!!!");
			
			esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end");

		}
		else if(!strcmp(mydata, "n:connected\r\n")){
			printf("RECONNECTING NOW!!!");
					
			esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end");

		}
		printf(mydata);
		ssd1306_clear();
		ssd1306_set_page_address(0);
		ssd1306_write_text(mydata);
		
		
	}

}