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

	startFTP();
	startWebServer();
}
Exemplo n.º 2
0
void web_run() {
	WifiStation.enable(true);
	server.listen(80);
	server.addPath("/driver/pos", web_cb_driver_pos);
	server.addPath("/driver/setpos", web_cb_driver_setpos);
	server.addPath("/driver/forward", web_cb_driver_forward);
	server.addPath("/driver/backward", web_cb_driver_backward);
	server.addPath("/driver/stop", web_cb_driver_stop);
	server.addPath("/scan", web_cb_start_scan);
	server.addPath("/scanStatus", web_cb_scan_status);
	server.addPath("/connect", web_cb_connect);
	server.setDefaultHandler(onFile);
	startFTP();
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	int c, error = 0;
	struct hist_data h;
	int retlog;
	char tmp[MAXBUFSIZ];
	char *fullurl;
	extern char *optarg;
	extern int optind;
	sigset_t set;

	main_tid = pthread_self();
	/* Allocate heap for download request	
	 * struct request stores all the information that might be
	 * of interest
	 */
	req = (struct request *)calloc(1, sizeof(struct request));

	/* This is required because if download is aborted before
	 * this is initialized, problems will occur
	 */
	wthread = NULL;

	/* except from signal handler thread, 
	 * no other thread is receiving signals!
	 * No signals are caught here since we need to save download job only
	 * after wthread structures are initialized.
	 * TODO:: We need to create helper thread as soon as head request is over
	 * since the user might wish to stop downloading as soon as he sees the
	 * content length.
	 */
	sigfillset(&set);
	pthread_sigmask(SIG_BLOCK, &set, NULL);

	/* Safe to exit before download starts.
	 * This is set back to DEFERRED before creating helper thread because
	 * we want this to exit only at certain safe points specified using
	 * pthread_testcancel().
	 * Helper thread is started just before creating worker threads and after
	 * wthread structures are initialized. Only after this point do we need to
	 * save download job if an interrupt comes - not before. Helper thread exists
	 * only to catch SIGINT and to save download job. It doesn't make sense to
	 * start it before wthread structures are initialized!
	 */
	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);


	/* Read the RC file if exist	*/
	readrc();


	/* If set in rc file	*/
	if (preferredthread != -1)
		nthreads = preferredthread;

	while (!error && (c = getopt(argc,argv,"p:l:n:hfv")) != -1) {
		switch(c) {
			case 'p':
				req->port = atoi(optarg);
				break;
			case 'l':
				strncpy(req->lfile, optarg, MAXBUFSIZ -1);
				break;
			case 'n':
				fsuggested = 1;
				if ((nthreads = atoi(optarg)) > MAXTHREADS) {
					Log("Error: Maximum # of threads allowed is %d\n", MAXTHREADS);
					exit(1);
				}
				break;
			case 'h':
				printf("%s\n", PROGVERSION);
				usage();
				exit(0);
				break;
			case 'v':
				printf("%s\nby Murat BALABAN <*****@*****.**>\n", PROGVERSION);
				exit(0);
				break;
			default:
				error = 1;
				usage();
				exit(1);
				break;
		}
	}

	if (error) {
		usage();
		exit(1);
	}

	if (fsuggested == 1 && nthreads == 0) {
		fprintf(stderr, "ERROR: -f and -n should be used together!, exiting...\n");
		usage();
		exit(1);
	}

	if (argc == 2) 		/* If only url is supplied... */
		fullurl = strdup(argv[1]);
	else
	if (optind < argc)
		if (argc > 2)
			fullurl = strdup(argv[optind]);
		else {
			usage();
			exit(1);
		}
	else
	if (optind == argc) {
		usage();
		exit(1);
	}

	parse_url(fullurl, req);


	if(strlen(req->lfile) == 0)
		strncpy(req->lfile, req->file, MAXBUFSIZ - 2);

	getcwd(tmp, MAXBUFSIZ -2);
	strncpy(tmp+strlen(tmp), "/", MAXBUFSIZ - strlen(tmp) - 2);
	strncpy(tmp+strlen(tmp), req->lfile, MAXBUFSIZ - strlen(tmp) - 3);
	strncpy(req->lfile, tmp, MAXBUFSIZ - 2);

	/* If a log file for a previous try has been found, read it and
	 * resume the download job (resume_get), otherwise, start with
	 * a clean job (get)
	 *
	 * Logfile is of the pattern: aget-$file_name.log
	 */
	switch(req->proto) {
		case PROTO_HTTP:
			if ((retlog = read_log(&h)) != -1)
				resumeDownload(&h, PROTO_HTTP);
			else
				startHTTP(req);
			break;
		case PROTO_FTP:
			if ((retlog = read_log(&h)) != -1)
				resumeDownload(&h, PROTO_FTP);
			else
				startFTP(req);
			break;
	}
	return 0;
}
Exemplo n.º 4
0
// Will be called when system initialization was completed
void ICACHE_FLASH_ATTR startServers()
{
	startFTP();
	startWebServer();
}