void setup() { pinMode(CH_PD, OUTPUT); pinMode(ESP8266_RST, OUTPUT); pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_LED_PIN, OUTPUT); pinMode(LEFT_LIGHT, OUTPUT); pinMode(RIGHT_LIGHT, OUTPUT); light_blink_counter = -1; systick_enable(); esp8266_serial_init(&esp8266_serial, ESP_SERIAL, ESP_SERIAL_BAUD); if (!esp8266_serial) { debug("Serial Initialization failed, no memory\r\n"); return; } RFID_READER.begin(RFID_BAUD_RATE); kaa_client_props_t props; props.serial = esp8266_serial; props.wifi_ssid = SSID; props.wifi_pswd = PWD; bool need_deallocation; ext_get_endpoint_public_key(&props.kaa_public_key, &props.kaa_public_key_length, &need_deallocation); kaa_error_t error = kaa_client_create(&kaa_client, &props); if (error) { debug("Failed to init Kaa client, error code %d\r\n", error); return; } error = kaa_user_manager_default_attach_to_user(kaa_client_get_context(kaa_client)->user_manager , KAA_USER_ID , KAA_USER_ACCESS_TOKEN); if (error) { debug("Failed to attach to user '%s', error code %d\r\n", KAA_USER_ID, error); return; } }
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); } }